Well, I looked in the API documentation of the releaseConnection()
method and it says:

"After this method is called, getResponseBodyAsStream() will return
null, and getResponseBody() and getResponseBodyAsString() may return
null."

The documentation doesn't say why you would want to use that method, and
I don't know enough about HTTP to say what it's supposed to achieve, but
I would take out the line that calls that method. I don't use it in my
code that also uses Apache HttpClient.

Regards
PC2

-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx
[mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of Kara Burkhalter
Sent: April 10, 2008 05:46
To: java400-l@xxxxxxxxxxxx
Subject: HTTPClient help

I am trying to redirect to a URL from a servlet using POST. I get no
error messages but my page doesn't go anywhere. My print statement at
the end prints "ResponseBody = null". What am I doing wrong? This is my
code that I have (note I have removed actual URL for security
reasons)....

//Create an instance of HttpClient.
HttpClient client = new HttpClient();

// Create a method instance.
PostMethod post = new PostMethod("https://URL";);
NameValuePair[] data = {
new NameValuePair("agent_id", username),
new NameValuePair("password", pwd),
new NameValuePair("poltyp", type),
new NameValuePair("polno", policy)
};
post.setRequestBody(data);

try {
client.executeMethod(post);
post.releaseConnection();

String in =
post.getResponseBodyAsString();
System.out.println("ResponseBody = " +
in);

}
catch(HttpException e) {
e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}

Thank you for your help!
Kara


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
--
This is the Java Programming on and around the iSeries / AS400
(JAVA400-L) mailing list To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/java400-l.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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

This mailing list archive is Copyright 1997-2022 by midrange.com 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.