I want to POST userid, password, and some hidden-field information to a web
page given by URL=urlB. The web page, however, checks my "Referer" header
value to make sure that it says "Referer : urlA". I have no problem GETting
urlB with the following code snippet:
GetMethod hmethod = new GetMethod(urlB);
hmethod.addRequestHeader("Referer",urlA);
but how do I POST to urlB?
The usual sequence:
PostMethod pmethod = new PostMethod(urlB);
NameValuePair[] data = {
new NameValuePair("userid","xxxxxx"),
new NameValuePair("password","abcd"),
new NameValuePair("hiddenfieldname1", hiddenfieldvalue1),
new NameValuePair("hiddenfieldname2", "hiddenfieldvalue2")
};
pmethod.addParameters(data);
int statusCode2 = client.executeMethod(pmethod);
etc.
executes properly and gives me a statusCode2 of 200; but the web site gives
me an error message because it checks for a "Referer" name-value pair and does
not find a "Referer:urlA". Is there a way that I can add "Referer"
information to the PostMethod requestHeader as I was able to do with the
GetMethod?
I have tried adding the line:
pmethod.addRequestHeader("Referer",urlA);
after the line:
pmethod.addParameters(data);
but that results in a statusCode2 of 405, "Method Not Allowed."
Any ideas?
Jerry Yurow