hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvomalley <tvomal...@gmail.com>
Subject Moving from 2.0.2 to 3.0 - Connection is not open
Date Tue, 24 Apr 2007 13:59:27 GMT

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


Mime
View raw message