You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by tvomalley <tv...@gmail.com> on 2007/04/24 15:59:27 UTC
Moving from 2.0.2 to 3.0 - Connection is not open
I'm moving from httpclient 2.0.2 to 3.0 and I found that with the 3.0 lib I
have to explicitly open the HTTPConnection before I execute the POSTMethod,
with the 2.0.2 lib the HTTPConnection opened when the POSTMethod executed.
Does that sound correct or did I miss something? Here's both snippets of
code:
2.0.2:
PostMethod post = new
PostMethod("http://localhost:8080/mycontext");
post.setRequestHeader(HttpFields.__Accept,
"application/soap+xml");
post.setRequestHeader(HttpFields.__UserAgent, "MY Client");
post.setRequestHeader(HttpFields.__ContentType, "text/xml;
charset=utf-8");
post.setRequestHeader("SOAPAction", "\"\"");
post.setRequestBody(new ByteArrayInputStream(message));
post.setRequestContentLength(message.length);
org.apache.commons.httpclient.URI uri = post.getURI();
HttpConnection m_http =
new HttpConnection(
uri.getHost(),
uri.getPort(),
Protocol.getProtocol(uri.getScheme()));
HttpState m_state = new HttpState();
int responseCode = post.execute(m_state, m_http);
3.0:
PostMethod post = new
PostMethod("http://localhost:8080/mycontext");
post.setRequestHeader(HttpFields.__Accept,
"application/soap+xml");
post.setRequestHeader(HttpFields.__UserAgent, "MY Client");
post.setRequestHeader(HttpFields.__ContentType, "text/xml;
charset=utf-8");
post.setRequestHeader("SOAPAction", "\"\"");
post.setRequestEntity(new InputStreamRequestEntity(new
ByteArrayInputStream(message), message.length));
org.apache.commons.httpclient.URI uri = post.getURI();
m_http =
new HttpConnection(
uri.getHost(),
uri.getPort(),
Protocol.getProtocol(uri.getScheme()));
HttpState m_state = new HttpState();
if (!m_http.isOpen()) {
m_http.open();
}
int responseCode = post.execute(m_state, m_http);
Thanks
--
View this message in context: http://www.nabble.com/Moving-from-2.0.2-to-3.0---Connection-is-not-open-tf3638854.html#a10161560
Sent from the HttpClient-User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: Moving from 2.0.2 to 3.0 - Connection is not open
Posted by Roland Weber <RO...@de.ibm.com>.
Hello,
> I'm moving from httpclient 2.0.2 to 3.0 and I found that with the 3.0
lib I
> have to explicitly open the HTTPConnection before I execute the
POSTMethod,
> with the 2.0.2 lib the HTTPConnection opened when the POSTMethod
executed.
> Does that sound correct or did I miss something?
You're not supposed to call method.execute(...) at all.
You should be calling client.executeMethod(method,...), then
the HttpClient will take care of opening the connection.
hope that helps,
Roland