My code (below) logs into a website, then post data to a form on a page only accessible after I log in. The first post (log in) succeeds, but I'm hung up on the second. I have included the wire logging after the code, so you can see that nothing seems to happen after I send the content for the second post method. Any suggestions?
My code hangs on
client.executeMethod(post2);
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("https://myaccount.poivy.com/clx/index.php");
NameValuePair[] data = {
new NameValuePair("username", "removed"),
new NameValuePair("password", "removed")
};
post.setRequestBody(data);
post.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
client.executeMethod(post);
Header[] headers = post.getResponseHeaders();
System.out.println(post.getResponseBodyAsString());
post.releaseConnection();
PostMethod post2 = new PostMethod("https://myaccount.poivy.com/clx/webcalls2.php");
for (Header header : headers)
post2.addRequestHeader(header);
NameValuePair[] data2 = {
new NameValuePair("anrphonenr", "+15555555"),
new NameValuePair("bnrphonenr", "+15555555")
};
post2.setRequestBody(data2);
post2.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
client.executeMethod(post2);
System.out.println(post2.getResponseBodyAsString());
Here is the wire logging, as you can see, nothing happens (it just hangs, waiting for a response) after the body content of the second post method is sent to the server:
2008/10/03 20:48:33:796 CDT [DEBUG] HttpClient - Java version: 1.6.0_07
2008/10/03 20:48:33:812 CDT [DEBUG] HttpClient - Java vendor: Sun Microsystems Inc.
2008/10/03 20:48:33:812 CDT [DEBUG] HttpClient - Java class path: C:\java\workspace\poivy_automated_callback\bin;C:\java\commons-httpclient-3.1\commons-httpclient-3.1.jar;C:\java\commons-logging-1.1.1\commons-logging-1.1.1.jar;C:\java\commons-codec-1.3\commons-codec-1.3.jar
2008/10/03 20:48:33:812 CDT [DEBUG] HttpClient - Operating system name: Windows XP
2008/10/03 20:48:33:812 CDT [DEBUG] HttpClient - Operating system architecture: x86
2008/10/03 20:48:33:812 CDT [DEBUG] HttpClient - Operating system version: 5.1
2008/10/03 20:48:33:890 CDT [DEBUG] HttpClient - SUN 1.6: SUN (DSA key/parameter generation; DSA signing; SHA-1, MD5 digests; SecureRandom; X.509 certificates; JKS keystore; PKIX CertPathValidator; PKIX CertPathBuilder; LDAP, Collection CertStores, JavaPolicy Policy; JavaLoginConfig Configuration)
2008/10/03 20:48:33:890 CDT [DEBUG] HttpClient - SunRsaSign 1.5: Sun RSA signature provider
2008/10/03 20:48:33:890 CDT [DEBUG] HttpClient - SunJSSE 1.6: Sun JSSE provider(PKCS12, SunX509 key/trust factories, SSLv3, TLSv1)
2008/10/03 20:48:33:890 CDT [DEBUG] HttpClient - SunJCE 1.6: SunJCE Provider (implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2, PBE, Diffie-Hellman, HMAC)
2008/10/03 20:48:33:890 CDT [DEBUG] HttpClient - SunJGSS 1.0: Sun (Kerberos v5, SPNEGO)
2008/10/03 20:48:33:890 CDT [DEBUG] HttpClient - SunSASL 1.5: Sun SASL provider(implements client mechanisms for: DIGEST-MD5, GSSAPI, EXTERNAL, PLAIN, CRAM-MD5; server mechanisms for: DIGEST-MD5, GSSAPI, CRAM-MD5)
2008/10/03 20:48:33:906 CDT [DEBUG] HttpClient - XMLDSig 1.0: XMLDSig (DOM XMLSignatureFactory; DOM KeyInfoFactory)
2008/10/03 20:48:33:906 CDT [DEBUG] HttpClient - SunPCSC 1.6: Sun PC/SC provider
2008/10/03 20:48:33:906 CDT [DEBUG] HttpClient - SunMSCAPI 1.6: Sun's Microsoft Crypto API provider
2008/10/03 20:48:33:906 CDT [DEBUG] DefaultHttpParams - Set parameter http.useragent = Jakarta Commons-HttpClient/3.1
2008/10/03 20:48:33:906 CDT [DEBUG] DefaultHttpParams - Set parameter http.protocol.version = HTTP/1.1
2008/10/03 20:48:33:906 CDT [DEBUG] DefaultHttpParams - Set parameter http.connection-manager.class = class org.apache.commons.httpclient.SimpleHttpConnectionManager
2008/10/03 20:48:33:906 CDT [DEBUG] DefaultHttpParams - Set parameter http.protocol.cookie-policy = default
2008/10/03 20:48:33:906 CDT [DEBUG] DefaultHttpParams - Set parameter http.protocol.element-charset = US-ASCII
2008/10/03 20:48:33:906 CDT [DEBUG] DefaultHttpParams - Set parameter http.protocol.content-charset = ISO-8859-1
2008/10/03 20:48:33:906 CDT [DEBUG] DefaultHttpParams - Set parameter http.method.retry-handler = org.apache.commons.httpclient.DefaultHttpMethodRetryHandler@787171
2008/10/03 20:48:33:906 CDT [DEBUG] DefaultHttpParams - Set parameter http.dateparser.patterns = [EEE, dd MMM yyyy HH:mm:ss zzz, EEEE, dd-MMM-yy HH:mm:ss zzz, EEE MMM d HH:mm:ss yyyy, EEE, dd-MMM-yyyy HH:mm:ss z, EEE, dd-MMM-yyyy HH-mm-ss z, EEE, dd MMM yy HH:mm:ss z, EEE dd-MMM-yyyy HH:mm:ss z, EEE dd MMM yyyy HH:mm:ss z, EEE dd-MMM-yyyy HH-mm-ss z, EEE dd-MMM-yy HH:mm:ss z, EEE dd MMM yy HH:mm:ss z, EEE,dd-MMM-yy HH:mm:ss z, EEE,dd-MMM-yyyy HH:mm:ss z, EEE, dd-MM-yyyy HH:mm:ss z]
2008/10/03 20:48:33:953 CDT [DEBUG] DefaultHttpParams - Set parameter http.protocol.cookie-policy = compatibility
2008/10/03 20:48:33:968 CDT [DEBUG] HttpConnection - Open connection to myaccount.poivy.com:443
2008/10/03 20:48:34:531 CDT [DEBUG] header - >> "POST /clx/index.php HTTP/1.1[\r][\n]"
2008/10/03 20:48:34:531 CDT [DEBUG] HttpMethodBase - Adding Host request header
2008/10/03 20:48:34:546 CDT [DEBUG] HttpMethodBase - Default charset used: ISO-8859-1
2008/10/03 20:48:34:546 CDT [DEBUG] HttpMethodBase - Default charset used: ISO-8859-1
2008/10/03 20:48:34:546 CDT [DEBUG] header - >> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
2008/10/03 20:48:34:546 CDT [DEBUG] header - >> "Host: myaccount.poivy.com[\r][\n]"
2008/10/03 20:48:34:546 CDT [DEBUG] header - >> "Content-Length: 40[\r][\n]"
2008/10/03 20:48:34:546 CDT [DEBUG] header - >> "Content-Type: application/x-www-form-urlencoded[\r][\n]"
2008/10/03 20:48:34:546 CDT [DEBUG] header - >> "[\r][\n]"
2008/10/03 20:48:34:546 CDT [DEBUG] content - >> "username=removed&password=removed"
2008/10/03 20:48:34:906 CDT [DEBUG] EntityEnclosingMethod - Request body sent
2008/10/03 20:48:38:390 CDT [DEBUG] header - << "HTTP/1.1 200 OK[\r][\n]"
2008/10/03 20:48:38:390 CDT [DEBUG] header - << "HTTP/1.1 200 OK[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - << "Date: Sat, 04 Oct 2008 01:48:27 GMT[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - << "Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8g[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - << "Set-Cookie: PHPSESSID=9ou1bib15h969jifd5eij9ek83; path=/; secure; HttpOnly[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - << "Expires: Thu, 19 Nov 1981 08:52:00 GMT[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - << "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - << "Pragma: no-cache[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - << "Set-Cookie: PHPSESSID=71j5amki520a86deb1o9490ap5; path=/; secure; HttpOnly[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - << "Set-Cookie: PHPSESSID=1qtqlinh45q22mc1houhaaqau6; path=/; secure; HttpOnly[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - << "Transfer-Encoding: chunked[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - << "Content-Type: text/html[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - << "[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] CookieSpec - Unrecognized cookie attribute: name=HttpOnly, value=null
2008/10/03 20:48:38:406 CDT [DEBUG] HttpMethodBase - Cookie accepted: "PHPSESSID=9ou1bib15h969jifd5eij9ek83"
2008/10/03 20:48:38:406 CDT [DEBUG] CookieSpec - Unrecognized cookie attribute: name=HttpOnly, value=null
2008/10/03 20:48:38:406 CDT [DEBUG] HttpMethodBase - Cookie accepted: "PHPSESSID=71j5amki520a86deb1o9490ap5"
2008/10/03 20:48:38:406 CDT [DEBUG] CookieSpec - Unrecognized cookie attribute: name=HttpOnly, value=null
2008/10/03 20:48:38:406 CDT [DEBUG] HttpMethodBase - Cookie accepted: "PHPSESSID=1qtqlinh45q22mc1houhaaqau6"
2008/10/03 20:48:38:406 CDT [DEBUG] HttpConnection - Input data available
2008/10/03 20:48:38:406 CDT [DEBUG] content - << "a"
2008/10/03 20:48:38:406 CDT [DEBUG] content - << "c"
2008/10/03 20:48:38:406 CDT [DEBUG] content - << "[\r]"
2008/10/03 20:48:38:406 CDT [DEBUG] content - << "[\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] content - << "<html><head><meta http-equiv="Refresh" content="0;url=index.php?part=menu&justloggedin=true"></head><body><a href="index.php?part=menu&justloggedin=true"></a></body></html>"
2008/10/03 20:48:38:406 CDT [DEBUG] content - << "[\r]"
2008/10/03 20:48:38:406 CDT [DEBUG] content - << "[\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] content - << "0"
2008/10/03 20:48:38:406 CDT [DEBUG] content - << "[\r]"
2008/10/03 20:48:38:406 CDT [DEBUG] content - << "[\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] content - << "[\r]"
2008/10/03 20:48:38:406 CDT [DEBUG] content - << "[\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - << "[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] HttpMethodBase - Resorting to protocol version default close connection policy
2008/10/03 20:48:38:406 CDT [DEBUG] HttpMethodBase - Should NOT close connection, using HTTP/1.1
2008/10/03 20:48:38:406 CDT [DEBUG] HttpConnection - Releasing connection back to connection manager.
2008/10/03 20:48:38:406 CDT [DEBUG] DefaultHttpParams - Set parameter http.protocol.cookie-policy = compatibility
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "POST /clx/webcalls2.php HTTP/1.1[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] HttpMethodBase - Adding Host request header
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "Date: Sat, 04 Oct 2008 01:48:27 GMT[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8g[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "Set-Cookie: PHPSESSID=9ou1bib15h969jifd5eij9ek83; path=/; secure; HttpOnly[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "Expires: Thu, 19 Nov 1981 08:52:00 GMT[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "Pragma: no-cache[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "Set-Cookie: PHPSESSID=71j5amki520a86deb1o9490ap5; path=/; secure; HttpOnly[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "Set-Cookie: PHPSESSID=1qtqlinh45q22mc1houhaaqau6; path=/; secure; HttpOnly[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "Transfer-Encoding: chunked[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "Content-Type: text/html[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "Host: myaccount.poivy.com[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "Cookie: PHPSESSID=1qtqlinh45q22mc1houhaaqau6[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] header - >> "[\r][\n]"
2008/10/03 20:48:38:406 CDT [DEBUG] HttpMethodBase - Default charset used: ISO-8859-1
2008/10/03 20:48:38:421 CDT [DEBUG] content - >> "anrphonenr=%2B15555555&bnrphonenr=%2B15555555"
2008/10/03 20:48:38:421 CDT [DEBUG] EntityEnclosingMethod - Request body sent