Hello Friends, I am developing a desktop application where I got to navigate to a web site. Previously I was getting "host parameter is null" exception while Post method. I solved the error by setting the host of the client - client.getHostConfiguration().setHost(Url, 443, "https"); & passed HostConfiguration object along with executing post method.
Now, I am facing another problem of "302 Found" response from post. Post runs without any error. This is my Post code: [code] public String POST(String url, NameValuePair[] data) { String res = ""; String URL = ymailSinupUrl + url; PostMethod method = new PostMethod(URL); // SET PROPERTIES method.getParams().setParameter("http.method.retry-handler", new DefaultHttpMethodRetryHandler(3, false)); method.setRequestHeader("User-agent", USER_AGENT); method.setRequestHeader("Accept", ACCEPT); method.setRequestHeader("Accept-Language", ACCEPT_LANG); // method.setRequestHeader("Accept-Encoding", ACCEPT_ENC); method.setRequestHeader("Accept-Charset", ACCEPT_CHAR); method.setRequestHeader("Keep-Alive", KEEP_ALIVE); method.setRequestHeader("Connection", CONNECTION); if (! "".equals(lastUrl)) method.setRequestHeader("Referer", lastUrl); if (connectMgr.getConnection(hc).isOpen() == true) System.out.println("Connection is OPEN"); else { System.out.println("Connection is ******************* NOT OPEN *************** "); } method.setRequestBody(data); int statusCode = 0; try { statusCode = client.executeMethod(hc, method); System.out.println("Register Send: " + method.getStatusLine().toString()); }catch (HttpException e) { method.releaseConnection(); System.out.println("HTTP EXception : " + e.getMessage()); }catch (IOException ie) { method.releaseConnection(); System.out.println("Error Exe Method - Post. Status Code = " + statusCode); ie.printStackTrace(); } if (statusCode != 200) { System.err.println((new StringBuilder()).append("POST Method failed: ").append(method.getStatusLine()).toString()); } else { InputStream inputStream = null; BufferedReader input = null; try { inputStream = method.getResponseBodyAsStream(); input = new BufferedReader(new InputStreamReader(inputStream)); String str; while((str = input.readLine()) != null) { res = (new StringBuilder()).append(res).append(str).toString(); } input.close(); } catch (IOException ie) { method.releaseConnection(); ie.printStackTrace(); } } System.out.println((new StringBuilder()).append("Status Code = ").append(statusCode).toString()); Header h; if (statusCode == 302) { h = method.getResponseHeader("Location"); System.out.println("Header = " + h.getValue()); } try { lastUrl = method.getURI().toString(); } catch (HttpException he) { he.printStackTrace(); }finally { method.releaseConnection(); } return res; } [/code] And this is the whole log, that I get from start [code] 2007/11/21 10:44:26:234 IST [DEBUG] HttpClient - Java version: 1.6.0_02 2007/11/21 10:44:26:250 IST [DEBUG] HttpClient - Java vendor: Sun Microsystems Inc. 2007/11/21 10:44:26:250 IST [DEBUG] HttpClient - Java class path: E:\Trupti\JakartaApache\commons-codec-1.3.jar;E:\Trupti\JakartaApache\commons-httpclient-3.0.1.jar;E:\Trupti\JakartaApache\commons-lang-2.3.jar;E:\Trupti\JakartaApache\commons-logging-1.1.jar;E:\Trupti\Projects\Sol Edad\Yname Maker\build\classes 2007/11/21 10:44:26:250 IST [DEBUG] HttpClient - Operating system name: Windows XP 2007/11/21 10:44:26:250 IST [DEBUG] HttpClient - Operating system architecture: x86 2007/11/21 10:44:26:250 IST [DEBUG] HttpClient - Operating system version: 5.1 2007/11/21 10:44:26:640 IST [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) 2007/11/21 10:44:26:640 IST [DEBUG] HttpClient - SunRsaSign 1.5: Sun RSA signature provider 2007/11/21 10:44:26:640 IST [DEBUG] HttpClient - SunJSSE 1.6: Sun JSSE provider(PKCS12, SunX509 key/trust factories, SSLv3, TLSv1) 2007/11/21 10:44:26:640 IST [DEBUG] HttpClient - SunJCE 1.6: SunJCE Provider (implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2, PBE, Diffie-Hellman, HMAC) 2007/11/21 10:44:26:640 IST [DEBUG] HttpClient - SunJGSS 1.0: Sun (Kerberos v5, SPNEGO) 2007/11/21 10:44:26:640 IST [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) 2007/11/21 10:44:26:640 IST [DEBUG] HttpClient - XMLDSig 1.0: XMLDSig (DOM XMLSignatureFactory; DOM KeyInfoFactory) 2007/11/21 10:44:26:640 IST [DEBUG] HttpClient - SunPCSC 1.6: Sun PC/SC provider 2007/11/21 10:44:26:640 IST [DEBUG] HttpClient - SunMSCAPI 1.6: Sun's Microsoft Crypto API provider 2007/11/21 10:44:26:640 IST [DEBUG] DefaultHttpParams - Set parameter http.useragent = Jakarta Commons-HttpClient/3.0.1 2007/11/21 10:44:26:656 IST [DEBUG] DefaultHttpParams - Set parameter http.protocol.version = HTTP/1.1 2007/11/21 10:44:26:671 IST [DEBUG] DefaultHttpParams - Set parameter http.connection-manager.class = class org.apache.commons.httpclient.SimpleHttpConnectionManager 2007/11/21 10:44:26:671 IST [DEBUG] DefaultHttpParams - Set parameter http.protocol.cookie-policy = rfc2109 2007/11/21 10:44:26:671 IST [DEBUG] DefaultHttpParams - Set parameter http.protocol.element-charset = US-ASCII 2007/11/21 10:44:26:671 IST [DEBUG] DefaultHttpParams - Set parameter http.protocol.content-charset = ISO-8859-1 2007/11/21 10:44:26:703 IST [DEBUG] DefaultHttpParams - Set parameter http.method.retry-handler = [EMAIL PROTECTED] 2007/11/21 10:44:26:703 IST [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] 2007/11/21 10:44:26:718 IST [DEBUG] DefaultHttpParams - Set parameter http.protocol.cookie-policy = null Landing on Signup Page 2007/11/21 10:44:26:812 IST [DEBUG] DefaultHttpParams - Set parameter http.method.rety-handler = [EMAIL PROTECTED] 2007/11/21 10:44:26:828 IST [DEBUG] HttpConnection - Open connection to edit.yahoo.com:443 2007/11/21 10:44:29:843 IST [DEBUG] header - >> "GET /registration?.intl=us&new=1&.done=http HTTP/1.1[\r][\n]" 2007/11/21 10:44:29:843 IST [DEBUG] HttpMethodBase - Adding Host request header 2007/11/21 10:44:29:875 IST [DEBUG] header - >> "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20061201 Firefox/2.0.0.3 (Ubuntu-feisty)[\r][\n]" 2007/11/21 10:44:29:875 IST [DEBUG] header - >> "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5[\r][\n]" 2007/11/21 10:44:29:875 IST [DEBUG] header - >> "Accept-Language: en-US[\r][\n]" 2007/11/21 10:44:29:875 IST [DEBUG] header - >> "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7[\r][\n]" 2007/11/21 10:44:29:875 IST [DEBUG] header - >> "Keep-Alive: 300[\r][\n]" 2007/11/21 10:44:29:875 IST [DEBUG] header - >> "Connection: keep-alive[\r][\n]" 2007/11/21 10:44:29:875 IST [DEBUG] header - >> "Host: edit.yahoo.com[\r][\n]" 2007/11/21 10:44:29:875 IST [DEBUG] header - >> "[\r][\n]" 2007/11/21 10:44:31:671 IST [DEBUG] header - << "HTTP/1.1 200 OK[\r][\n]" 2007/11/21 10:44:31:687 IST [DEBUG] header - << "Date: Wed, 21 Nov 2007 05:14:30 GMT[\r][\n]" 2007/11/21 10:44:31:687 IST [DEBUG] header - << "Set-Cookie: B=1vb71it3k7flm&b=3&s=el; expires=Tue, 02-Jun-2037 20:00:00 GMT; path=/; domain=.yahoo.com[\r][\n]" 2007/11/21 10:44:31:687 IST [DEBUG] header - << "P3P: policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"[\r][\n]" 2007/11/21 10:44:31:687 IST [DEBUG] header - << "Cache-control: no-cache[\r][\n]" 2007/11/21 10:44:31:687 IST [DEBUG] header - << "Pragma: no-cache[\r][\n]" 2007/11/21 10:44:31:687 IST [DEBUG] header - << "Expires: 0[\r][\n]" 2007/11/21 10:44:31:687 IST [DEBUG] header - << "Connection: close[\r][\n]" 2007/11/21 10:44:31:687 IST [DEBUG] header - << "Transfer-Encoding: chunked[\r][\n]" 2007/11/21 10:44:31:687 IST [DEBUG] header - << "Content-Type: text/html[\r][\n]" 2007/11/21 10:44:31:765 IST [DEBUG] HttpMethodBase - Cookie accepted: "$Version=0; B=1vb71it3k7flm&b=3&s=el; $Path=/; $Domain=.yahoo.com" 2007/11/21 10:44:37:171 IST [DEBUG] HttpMethodBase - Should close connection in response to directive: close Status Code = 200 Got RESPONSE :- HTML Code POSTING FORM .... 2007/11/21 10:44:48:046 IST [DEBUG] DefaultHttpParams - Set parameter http.method.retry-handler = [EMAIL PROTECTED] Connection is ******************* NOT OPEN *************** 2007/11/21 10:44:59:765 IST [WARN] SimpleHttpConnectionManager - SimpleHttpConnectionManager being used incorrectly. Be sure that HttpMethod.releaseConnection() is always called and that only one thread and/or method is using this connection manager at a time. 2007/11/21 10:44:59:796 IST [DEBUG] HttpConnection - Open connection to edit.yahoo.com:443 2007/11/21 10:45:06:218 IST [DEBUG] header - >> "POST /registration?.intl=us&new=1&.done=http/registration;_ylt=A9G_XG22vkNHmYcADgCZ2PAI HTTP/1.1[\r][\n]" 2007/11/21 10:45:06:234 IST [DEBUG] HttpMethodBase - Adding Host request header 2007/11/21 10:45:06:265 IST [DEBUG] HttpMethodBase - Default charset used: ISO-8859-1 2007/11/21 10:45:06:484 IST [DEBUG] HttpMethodBase - Default charset used: ISO-8859-1 2007/11/21 10:45:06:687 IST [DEBUG] header - >> "User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20061201 Firefox/2.0.0.3 (Ubuntu-feisty)[\r][\n]" 2007/11/21 10:45:06:718 IST [DEBUG] header - >> "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5[\r][\n]" 2007/11/21 10:45:06:734 IST [DEBUG] header - >> "Accept-Language: en-US[\r][\n]" 2007/11/21 10:45:06:765 IST [DEBUG] header - >> "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7[\r][\n]" 2007/11/21 10:45:06:781 IST [DEBUG] header - >> "Keep-Alive: 300[\r][\n]" 2007/11/21 10:45:06:796 IST [DEBUG] header - >> "Connection: keep-alive[\r][\n]" 2007/11/21 10:45:06:828 IST [DEBUG] header - >> "Referer: https://edit.yahoo.com/registration?.intl=us&new=1&.done=http[\r][\n]" 2007/11/21 10:45:06:843 IST [DEBUG] header - >> "Host: edit.yahoo.com[\r][\n]" 2007/11/21 10:45:06:875 IST [DEBUG] header - >> "Cookie: $Version=0; B=1vb71it3k7flm&b=3&s=el; $Path=/; $Domain=.yahoo.com[\r][\n]" 2007/11/21 10:45:06:890 IST [DEBUG] header - >> "Content-Length: 697[\r][\n]" 2007/11/21 10:45:06:906 IST [DEBUG] header - >> "Content-Type: application/x-www-form-urlencoded[\r][\n]" 2007/11/21 10:45:06:921 IST [DEBUG] header - >> "[\r][\n]" 2007/11/21 10:45:08:062 IST [DEBUG] EntityEnclosingMethod - Request body sent 2007/11/21 10:45:08:421 IST [DEBUG] header - << "HTTP/1.1 302 Found[\r][\n]" 2007/11/21 10:45:08:468 IST [DEBUG] header - << "Date: Wed, 21 Nov 2007 05:15:07 GMT[\r][\n]" 2007/11/21 10:45:08:500 IST [DEBUG] header - << "P3P: policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"[\r][\n]" 2007/11/21 10:45:08:515 IST [DEBUG] header - << "Location: http://www.yahoo.com/[\r][\n]" 2007/11/21 10:45:08:531 IST [DEBUG] header - << "Connection: close[\r][\n]" 2007/11/21 10:45:08:546 IST [DEBUG] header - << "Transfer-Encoding: chunked[\r][\n]" 2007/11/21 10:45:08:562 IST [DEBUG] header - << "Content-Type: text/html[\r][\n]" 2007/11/21 10:45:08:578 IST [DEBUG] HttpMethodDirector - Redirect required 2007/11/21 10:45:08:593 IST [INFO] HttpMethodDirector - Redirect requested but followRedirects is disabled Register Send: HTTP/1.1 302 Found POST Method failed: HTTP/1.1 302 Found Status Code = 302 Header Location = http://www.yahoo.com/ 2007/11/21 10:45:32:046 IST [DEBUG] HttpMethodBase - Should close connection in response to directive: close 2007/11/21 10:45:32:062 IST [DEBUG] HttpConnection - Releasing connection back to connection manager. REPLY FROM POS = [/code] In post, you can see, a Redirect is required. Status code is "302 Found" & the response that I receive from Post is "" & the Locations is the home page. What do I do to solve this, why the post response is "". Am I missing any thing more here. Please help me out. Thanks -- View this message in context: http://www.nabble.com/How-to-rectify-%22302-Found%22-message-from-POST-method---tf4848183.html#a13871386 Sent from the HttpClient-User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]