Any help is greatly appreciated! I need to get this working before I have
this baby in a few weeks. I am trying to send data to a form using
HttpClient post method. I can sucessfully get there but I am not being
redirected. I am getting a status code of 200 instead of one in the 300s.
Do I need to put the actual submit button in the name value pair for the
post to get it to work? Am I missing something else? I'm not sure if its
my code or the URL I am going against. I know the URL will come up and if
I enter the data into the form and click submit it does redirect to the
new URL.


// Create an instance of HttpClient.
HttpClient client = new
response = null;

// Create a method
PostMethod post = new

NameValuePair[] data = {
new NameValuePair("agent_id", username),
new NameValuePair("password", pwd),
new NameValuePair("poltyp", type),
new NameValuePair("polno", policy) };

System.out.println("requestBody =" + data.toString());

int statuscode =
"Statuscode = " + statuscode);

if ((statuscode ==
|| (statuscode == HttpStatus.SC_MOVED_PERMANENTLY)
|| (statuscode == HttpStatus.SC_SEE_OTHER)
|| (statuscode == HttpStatus.SC_TEMPORARY_REDIRECT)) {
header = post.getResponseHeader("location");

System.out.println("location=" + header.getValue());

(header != null) {
String newuri = header.getValue();

if ((newuri == null) || (newuri.equals(""))) {
newuri = "/";

GetMethod redirect = new GetMethod(newuri);

if (newuri.indexOf("jsessionid=") > -1) {
String jsessionid = newuri.substring(newuri
.indexOf("jsessionid=") +
11, newuri.length());

response.addHeader("Set-Cookie", "JSESSIONID="
+ jsessionid + ";Path="


This message may contain confidential or proprietary information and is
intended only for the person(s) to whom it is addressed. Any use,
distribution, copying or disclosure of confidential information by any
other person is strictly prohibited. If you have received this message in
error, please notify the e-mail sender immediately, and delete the
original message without making a copy. For information on the UW
Foundation's privacy policy, please visit:
UW Foundation Privacy Policy

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2022 by and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.