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 Henry Wijono <hw...@gmail.com> on 2006/06/21 05:48:07 UTC

Cookie and Post Issue..

Hello..

How can i login from one page to another? The first page is giving a login
error, not accepting cookie. The second code allows me to login to the site.
But the browser shows a local path to the servlet instead of redirecting to
the urlC. I think it allows me to login to the second site, but not the
first.

Below is snipet of my code.. your help/direction is greatly appreciated.
Thanks.

String urlA = "https://abc.com/user/dologin.php";
String urlB = "https://abc.com/index.php";
String urlC = "https://abc.com/inventory/index.php";

                // Set cookie parameter to a single header
                httpClient.getParams().setBooleanParameter(
HttpMethodParams.SINGLE_COOKIE_HEADER, true);

                //PostMethod method = new PostMethod(urlA);
                GetMethod method = new GetMethod(urlA);
                NameValuePair[] putData = {
                    new NameValuePair("username", username),
                    new NameValuePair("password", password),
                    new NameValuePair("section", "inventory"),
                    new NameValuePair("Content-Length", "1500"),
                    new NameValuePair("Referer", "
https://abc.com/user/dologin.php"),
                    new NameValuePair("method", "post"),
                    new NameValuePair("swpcookie", "ABC"),
                    new NameValuePair("Content-Type",
"application/x-www-form-urlencoded; charset=UTF8"),
                    new NameValuePair("Content-Style-Type", "text/css"),
                    new NameValuePair("User-Agent", "Mozilla/5.0 (Windows;
U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4" ),
                    new NameValuePair("Cache-Control", "private"),
                    new NameValuePair("pragma", "no-cache")};

                    // POST
                    //method.setRequestBody(putData);
                    // GET
                    method.setQueryString(putData);

                    //write out the request headers
                    System.out.println("*** Request ***");
                    System.out.println("Request Follow Redirects: " +
method.getFollowRedirects());
                    System.out.println("Request URI: " + method.getURI());
                    System.out.println("Request Path: " + method.getPath());
                    System.out.println("Request Query: " +
method.getQueryString());
                    Header[] requestHeaders1 = method.getRequestHeaders();
                    for (int i=0; i < requestHeaders1.length; i++){
                        System.out.print("Request Headers: " +
requestHeaders1[i]);
                    }

                    //write out the response headers
                    System.out.println("*** Response ***");
                    System.out.println("Status Line: " +
method.getStatusLine());
                    Header[] responseHeaders1 = method.getResponseHeaders();
                    for (int i=0; i<responseHeaders1.length; i++){
                        System.out.print(responseHeaders1[i]);
                    }

                // Execute the method.
                statusCode = httpClient.executeMethod(method);
                if (statusCode != HttpStatus.SC_OK) {
                    System.err.println("Method failed: " +
method.getStatusLine());
                }

            is = new InputStreamReader(method.getResponseBodyAsStream());
            in = new BufferedReader(is);

            for ( String s; ( s = in.readLine() ) != null; )
                System.out.println( " OUTPUT A " + s );

*****************************************************************************
LOG
*****************************************************************************
DEBUG [org.apache.commons.httpclient.params.DefaultHttpParams] Set parameter
http.protocol.single-cookie-header = true
DEBUG [org.apache.commons.httpclient.methods.GetMethod] enter
GetMethod(String)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.setQueryString(NameValuePair[])
*** Request ***
Request Follow Redirects: true
Request URI:
https://abc.com/user/dologin.php?username=hwijono&password=Password1&section=inventory&Content-Length=1500&Referer=https%3A%2F%2Fabc.com%2Fuser%2Fdologin.php&method=post&swpcookie=ABC&Content-Type=application%2Fx-www-form-urlencoded%3B+charset%3DUTF8&Content-Style-Type=text%2Fcss&User-Agent=Mozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+5.1%3B+en-US%3B+rv%3A1.8.0.4%29+Gecko%2F20060508+Firefox%2F1.5.0.4&Cache-Control=private&pragma=no-cache
Request Path: /v240/user/dologin.php
Request Query:
username=hwijono&password=Password1&section=inventory&Content-Length=1500&Referer=https%3A%2F%2Fabc.com%2Fuser%2Fdologin.php&method=post&swpcookie=ABC&Content-Type=application%2Fx-www-form-urlencoded%3B+charset%3DUTF8&Content-Style-Type=text%2Fcss&User-Agent=Mozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+5.1%3B+en-US%3B+rv%3A1.8.0.4%29+Gecko%2F20060508+Firefox%2F1.5.0.4&Cache-Control=private&pragma=no-cache
*** Response ***
Status Line: null
DEBUG [org.apache.commons.httpclient.HttpClient] enter
HttpClient.executeMethod(HttpMethod)
DEBUG [org.apache.commons.httpclient.HttpClient] enter
HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState)
DEBUG [org.apache.commons.httpclient.HttpMethodDirector] Attempt number 1 to
process request
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.open()
DEBUG [org.apache.commons.httpclient.HttpConnection] Open connection to
abc.com:443
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.execute(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.writeRequest(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.writeRequestLine(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.generateRequestLine(HttpConnection, String, String, String,
String)
DEBUG [httpclient.wire.header] >> "GET
/user/dologin.php?username=hwijono&password=Password1&section=inventory&Content-Length=1500&Referer=https%3A%2F%2Fabc.com%2Fuser%2Fdologin.php&method=post&swpcookie=ABC&Content-Type=application%2Fx-www-form-urlencoded%3B+charset%3DUTF8&Content-Style-Type=text%2Fcss&User-Agent=Mozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+5.1%3B+en-US%3B+rv%3A1.8.0.4%29+Gecko%2F20060508+Firefox%2F1.5.0.4&Cache-Control=private&pragma=no-cache
HTTP/1.1[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.print(String)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addRequestHeaders(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] Adding Host request
header
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addCookieRequestHeader(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.getCookies()
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.match(String, int, String, boolean, Cookie[])
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.match(String, int, String, boolean, Cookie
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.formatCookieHeader(Cookie[])
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addProxyConnectionHeader(HttpState, HttpConnection)
DEBUG [httpclient.wire.header] >> "User-Agent: Jakarta
Commons-HttpClient/3.0.1[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.print(String)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [httpclient.wire.header] >> "Host: abc.com[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.print(String)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [httpclient.wire.header] >> "Cookie: $Version=0;
swpcookie=hwijono_8e1289f6f68b940adaac979eecbcc025; $Path=/[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.print(String)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.writeLine()
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [httpclient.wire.header] >> "[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.flushRequestOutputStream()
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readResponse(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readStatusLine(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.readLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [httpclient.wire.header] << "HTTP/1.1 200 OK[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readResponseHeaders(HttpState,HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.getResponseInputStream()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HeaderParser.parseHeaders(InputStream, String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [httpclient.wire.header] << "Date: Wed, 21 Jun 2006 03:24:32
GMT[\r][\n]"
DEBUG [httpclient.wire.header] << "Server: Apache/2.0.52 (Red Hat)[\r][\n]"
DEBUG [httpclient.wire.header] << "X-Powered-By: PHP/4.4.0[\r][\n]"
DEBUG [httpclient.wire.header] << "Set-Cookie:
swpcookie=hwijono_8a61f22a2cfad0fa99cfa7fe0f1f26fe; path=/[\r][\n]"
DEBUG [httpclient.wire.header] << "Set-Cookie: pwdexp=deleted; expires=Tue,
21 Jun 2005 03:24:31 GMT; path=/[\r][\n]"
DEBUG [httpclient.wire.header] << "Content-Length: 780[\r][\n]"
DEBUG [httpclient.wire.header] << "Connection: close[\r][\n]"
DEBUG [httpclient.wire.header] << "Content-Type: text/html;
charset=utf-8[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.processResponseHeaders(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.parse(String, port, path, boolean, String)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.parse(String, port, path, boolean, Header)
DEBUG [org.apache.commons.httpclient.HeaderElement] enter
HeaderElement.parseElements(char[])
DEBUG [org.apache.commons.httpclient.Cookie] enter Cookie(String, String,
String, String, Date, boolean)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.validate(String, int, String, boolean, Cookie)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.validate(String, port, path, boolean, Cookie)
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.addCookie
(Cookie)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.formatCookie(Cookie)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] Cookie accepted:
"$Version=0; swpcookie=hwijono_8a61f22a2cfad0fa99cfa7fe0f1f26fe; $Path=/"
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.parse(String, port, path, boolean, String)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.parse(String, port, path, boolean, Header)
DEBUG [org.apache.commons.httpclient.Cookie] enter Cookie(String, String,
String, String, Date, boolean)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.validate(String, int, String, boolean, Cookie)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.validate(String, port, path, boolean, Cookie)
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.addCookie
(Cookie)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.formatCookie(Cookie)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] Cookie accepted:
"$Version=0; pwdexp=deleted; $Path=/"
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readResponseBody(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readResponseBody(HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.getResponseInputStream()
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.canResponseHaveBody(int)
 OUTPUT A <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
 OUTPUT A <!--"http://www.w3.org/TR/html4/strict.dtd"-->
 OUTPUT A <html>
 OUTPUT A <head>
 OUTPUT A <title>ABC</title>
 OUTPUT A <meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
 OUTPUT A <link rel=STYLESHEET type="text/css" href="
https://abc.com/lib/en.css" title="">
 OUTPUT A <script language="javascript">function submitform() {
document.frmdologin.submit(); }</script></head>
 OUTPUT A <body onload="submitform();"><center><b>Logging in...please
wait</b></center>
 OUTPUT A    <form name="frmdologin" method="post" action="
https://abc.com/inventory/index.php">
 OUTPUT A       <input type="hidden" name="message" value="Your browser is
not accepting the login cookie.  Please enable cookies in your browser.">
 OUTPUT A    </form>
 OUTPUT A </body>
 OUTPUT A </html>
DEBUG [org.apache.commons.httpclient.HttpMethodBase] Should close connection
in response to directive: close
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.close()
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.closeSockedAndStreams()
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.releaseConnection()
DEBUG [org.apache.commons.httpclient.HttpConnection] Releasing connection
back to connection manager.
DEBUG [org.apache.commons.httpclient.methods.GetMethod] enter
GetMethod(String)
 COOKIE
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.getCookies()
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.formatCookie(Cookie)
 - swpcookie=hwijono_8a61f22a2cfad0fa99cfa7fe0f1f26fe
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.formatCookie(Cookie)
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.addCookies
(Cookie[])
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.addCookie
(Cookie)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.setQueryString(NameValuePair[])
DEBUG [org.apache.commons.httpclient.params.DefaultHttpParams] Set parameter
http.method.retry-handler =
org.apache.commons.httpclient.DefaultHttpMethodRetryHandler@159ea8e
DEBUG [org.apache.commons.httpclient.HttpClient] enter
HttpClient.executeMethod(HttpMethod)
DEBUG [org.apache.commons.httpclient.HttpClient] enter
HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState)
DEBUG [org.apache.commons.httpclient.HttpMethodDirector] Attempt number 1 to
process request
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.open()
DEBUG [org.apache.commons.httpclient.HttpConnection] Open connection to
abc.com:443
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.execute(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.writeRequest(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.writeRequestLine(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.generateRequestLine(HttpConnection, String, String, String,
String)
DEBUG [httpclient.wire.header] >> "GET
/user/dologin.php?username=hwijono&password=Password1&Content-Length=1500&Referer=https%3A%2F%2Fabc.com%2Fuser%2Fdologin.php&method=post&swpcookie=swpcookie%3Dhwijono_8a61f22a2cfad0fa99cfa7fe0f1f26fe&Content-Type=application%2Fx-www-form-urlencoded%3B+charset%3DUTF8&Content-Style-Type=text%2Fcss&User-Agent=Mozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+5.1%3B+en-US%3B+rv%3A1.8.0.4%29+Gecko%2F20060508+Firefox%2F1.5.0.4&Cache-Control=private&pragma=no-cache
HTTP/1.1[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.print(String)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addRequestHeaders(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] Adding Host request
header
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addCookieRequestHeader(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.getCookies()
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.match(String, int, String, boolean, Cookie[])
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.match(String, int, String, boolean, Cookie
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.formatCookieHeader(Cookie[])
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addProxyConnectionHeader(HttpState, HttpConnection)
DEBUG [httpclient.wire.header] >> "User-Agent: Jakarta
Commons-HttpClient/3.0.1[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.print(String)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [httpclient.wire.header] >> "Host: abc.com[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.print(String)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [httpclient.wire.header] >> "Cookie: $Version=0;
swpcookie=hwijono_8a61f22a2cfad0fa99cfa7fe0f1f26fe; $Path=/[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.print(String)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.writeLine()
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [httpclient.wire.header] >> "[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.flushRequestOutputStream()
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readResponse(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readStatusLine(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.readLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [httpclient.wire.header] << "HTTP/1.1 200 OK[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readResponseHeaders(HttpState,HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.getResponseInputStream()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HeaderParser.parseHeaders(InputStream, String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [httpclient.wire.header] << "Date: Wed, 21 Jun 2006 03:24:32
GMT[\r][\n]"
DEBUG [httpclient.wire.header] << "Server: Apache/2.0.52 (Red Hat)[\r][\n]"
DEBUG [httpclient.wire.header] << "X-Powered-By: PHP/4.4.0[\r][\n]"
DEBUG [httpclient.wire.header] << "Set-Cookie:
swpcookie=hwijono_8a61f22a2cfad0fa99cfa7fe0f1f26fe; path=/[\r][\n]"
DEBUG [httpclient.wire.header] << "Set-Cookie: pwdexp=deleted; expires=Tue,
21 Jun 2005 03:24:31 GMT; path=/[\r][\n]"
DEBUG [httpclient.wire.header] << "Content-Length: 771[\r][\n]"
DEBUG [httpclient.wire.header] << "Connection: close[\r][\n]"
DEBUG [httpclient.wire.header] << "Content-Type: text/html;
charset=utf-8[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.processResponseHeaders(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.parse(String, port, path, boolean, String)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.parse(String, port, path, boolean, Header)
DEBUG [org.apache.commons.httpclient.HeaderElement] enter
HeaderElement.parseElements(char[])
DEBUG [org.apache.commons.httpclient.Cookie] enter Cookie(String, String,
String, String, Date, boolean)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.validate(String, int, String, boolean, Cookie)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.validate(String, port, path, boolean, Cookie)
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.addCookie
(Cookie)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.formatCookie(Cookie)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] Cookie accepted:
"$Version=0; swpcookie=hwijono_8a61f22a2cfad0fa99cfa7fe0f1f26fe; $Path=/"
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.parse(String, port, path, boolean, String)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.parse(String, port, path, boolean, Header)
DEBUG [org.apache.commons.httpclient.Cookie] enter Cookie(String, String,
String, String, Date, boolean)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.validate(String, int, String, boolean, Cookie)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.validate(String, port, path, boolean, Cookie)
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.addCookie
(Cookie)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.formatCookie(Cookie)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] Cookie accepted:
"$Version=0; pwdexp=deleted; $Path=/"
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readResponseBody(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readResponseBody(HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.getResponseInputStream()
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.canResponseHaveBody(int)
*** Request ***
Request Follow Redirects: true
Request URI:
https://abc.com/user/dologin.php?username=hwijono&password=Password1&Content-Length=1500&Referer=https%3A%2F%2Fabc.com%2Fuser%2Fdologin.php&method=post&swpcookie=swpcookie%3Dhwijono_8a61f22a2cfad0fa99cfa7fe0f1f26fe&Content-Type=application%2Fx-www-form-urlencoded%3B+charset%3DUTF8&Content-Style-Type=text%2Fcss&User-Agent=Mozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+5.1%3B+en-US%3B+rv%3A1.8.0.4%29+Gecko%2F20060508+Firefox%2F1.5.0.4&Cache-Control=private&pragma=no-cache
Request Path: /user/dologin.php
Request Query:
username=hwijono&password=Password1&Content-Length=1500&Referer=https%3A%2F%2Fabc.com%2Fuser%2Fdologin.php&method=post&swpcookie=swpcookie%3Dhwijono_8a61f22a2cfad0fa99cfa7fe0f1f26fe&Content-Type=application%2Fx-www-form-urlencoded%3B+charset%3DUTF8&Content-Style-Type=text%2Fcss&User-Agent=Mozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+5.1%3B+en-US%3B+rv%3A1.8.0.4%29+Gecko%2F20060508+Firefox%2F1.5.0.4&Cache-Control=private&pragma=no-cache
Request Headers: User-Agent: Jakarta Commons-HttpClient/3.0.1
Request Headers: Host: abc.sentienthealth.com
Request Headers: Cookie: $Version=0;
swpcookie=hwijono_8a61f22a2cfad0fa99cfa7fe0f1f26fe; $Path=/
*** Response ***
Status Line: HTTP/1.1 200 OK
Date: Wed, 21 Jun 2006 03:24:32 GMT
Server: Apache/2.0.52 (Red Hat)
X-Powered-By: PHP/4.4.0
Set-Cookie: swpcookie=hwijono_8a61f22a2cfad0fa99cfa7fe0f1f26fe; path=/
Set-Cookie: pwdexp=deleted; expires=Tue, 21 Jun 2005 03:24:31 GMT; path=/
Content-Length: 771
Connection: close
Content-Type: text/html; charset=utf-8
DEBUG [org.apache.commons.httpclient.HttpMethodBase] Should close connection
in response to directive: close
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.close()
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.closeSockedAndStreams()
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.releaseConnection()
DEBUG [org.apache.commons.httpclient.HttpConnection] Releasing connection
back to connection manager.



-- 
Henry Wijono <:]]><

Re: Cookie and Post Issue..

Posted by Roland Weber <ht...@dubioso.net>.
Hello Henry,

please sit back, relax, and then explain in detail what you
are trying to do. I assumed that you are interacting with
a web page from a browser, and want to do the same thing
automatically from an application. But I am obviously wrong,
since that does not explain the existence of a servlet.

In response to some of your questions: if you have HttpClient
configured to automatically follow redirects, you won't see
30x response codes in the application.
In the wire log you sent, I can see that the server is sending
a page with some JavaScript that is auto-executed by browsers:

<script language="javascript">function submitform() {
document.frmdologin.submit(); }</script></head>
<body onload="submitform();"><center><b>Logging in...please
wait</b></center>
  <form name="frmdologin" method="post" action="
https://abc.com/v240/inventory/index.php">
     <input type="hidden" name="message" value="Your browser is not
accepting the login cookie.  Please enable cookies in your browser.">
  </form>
</body>

HttpClient is not going to do that for you. You'll have to send
another POST request to the URL given in the action= attribute,
with the parameters from that form. I don't think that the value
of the "message" parameter matters much, but you never know
until you tried.

You have sent some code that is absolutely pointless:

    Cookie[] cookies = httpClient.getState().getCookies();
    if (cookies.length == 0) {
        System.out.println("None");
    } else {
        for (int i = 0; i < cookies.length; i++) {
            System.out.println(" - " + cookies[i].toExternalForm());
            httpClient.getState().addCookie(cookies[i]);
        }
    }

Have a look at the else{} block - why are you putting
the cookies into the state from which you just got them?

Regarding URLs from the address bar, the primer says that you
can't determine the target address of a POST request reliably
by looking at the address bar. You can see an example above:
the server returns a page that implements a redirect by POST.
You're not even going to see more than a flicker in your browser
of that step. Afterwards, the address bar shows "/v240/..."
but the original POST request had to be sent to "/user/...".
The primer doesn't say you shouldn't use full URLs. It just says
you should get them from looking at the returned HTTP headers
and HTML code, not from looking at the address bar of the browser.
I'll review the primer some of these days, maybe I can point
that out more clearly.

hope that helps,
  Roland

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: Cookie and Post Issue..

Posted by Henry Wijono <hw...@gmail.com>.
A couple of point i didn't mention..
I use Jaas to connect for authentication. It resides in a servlet using a
different url.
Example, http://abc/servlet/connector and the report is in
htttp://abc/report.php
so in the Absolute Beginner Wikki, it said i can't use this URL from the
address bar of your browser! But if i don't use the full address, i won't
get to the right page..


On 6/21/06, Henry Wijono <hw...@gmail.com> wrote:
>
> Hello Roland,
>
> Thank you for the link. Yes, i read it. Though not understanding a 100%,
> it gives me a good idea of how it should interact.
>
> A question though.. this cookie from the output.. Status Code is 200. i
> don't see a redirection status code. Is that something a server will respond
> automatically with 303 or 307 status?
>
> At first page, the site goes to dologin.php then it will go to user.phpbefore going to the actual report. That's why I am confused whether there's
> some steps i am missing?
> I tried post then get, get and post, get and get. It's still giving
> disable cookie in browser. Though I can see the cookies are being passed
> between get and post. Thanks for your inputs...
>
> swpcookie=hwijono_bba3fbf67c33d39c289e014b46f88a49
>
> the code:
>
>
> GetMethod method = new GetMethod(urlA);
>                 NameValuePair[] putData = {
>                     new NameValuePair("username", username),
>                     new NameValuePair("password", password),
>                     new NameValuePair("loginid", username),
>
>                     new NameValuePair("section", "inventory"),
>                     new NameValuePair("Content-Length", "1500"),
>                     new NameValuePair("Referer", urlA),
>                     new NameValuePair("location", urlA),
>                     //new NameValuePair("method", "post"),
>
>                     //new NameValuePair("swpcookie", "ABC"),
>                     new NameValuePair("Content-Type",
> "application/x-www-form-urlencoded; charset=UTF8"),
>                     new NameValuePair("Content-Style-Type", "text/css"),
>                     new NameValuePair("User-Agent", "Mozilla/5.0 (Windows;
> U; Windows NT 5.1; en-US; rv: 1.8.0.4) Gecko/20060508 Firefox/1.5.0.4" ),
>                     new NameValuePair("Cache-Control", "private"),
>                     new NameValuePair("pragma", "no-cache"),
>                     new NameValuePair("Connection",
> "keep-alive")
>                 };
>
>                     // POST
>                     //method.setRequestBody(putData);
>                     // GET
>                     method.setQueryString(putData);
>
>                     //write out the request headers
>                     System.out.println("*** Request ***");
>                     System.out.println("Request Follow Redirects: " +
> method.getFollowRedirects());
>                     System.out.println("Request URI: " + method.getURI());
>                     System.out.println("Request Path: " + method.getPath
> ());
>                     System.out.println("Request Query: " +
> method.getQueryString());
>                     Header[] requestHeaders1 = method.getRequestHeaders();
>                     for (int i=0; i < requestHeaders1.length; i++){
>                         System.out.print("Request Headers: " +
> requestHeaders1[i]);
>                     }
>
>                     //write out the response headers
>                     System.out.println("*** Response ***");
>                     System.out.println("Status Line: " +
> method.getStatusLine());
>                     Header[] responseHeaders1 = method.getResponseHeaders
> ();
>                     for (int i=0; i<responseHeaders1.length; i++){
>                         System.out.print(responseHeaders1[i]);
>                     }
>
>                 // Execute the method.
>                 statusCode = httpClient.executeMethod(method);
>
>                 System.out.println(" *** STATUS CODE " + statusCode);
>
>                 if (statusCode != HttpStatus.SC_OK) {
>                     System.err.println("Method failed: " +
> method.getStatusLine());
>                 }
>
>             is = new InputStreamReader( method.getResponseBodyAsStream());
>             in = new BufferedReader(is);
>
>             for ( String s; ( s = in.readLine() ) != null; )
>                 System.out.println( s );
>
>             System.out.println("COOKIE 1 ");
>
>                 Cookie[] cookies = httpClient.getState().getCookies();
>                 if (cookies.length == 0) {
>                     System.out.println("None");
>                 } else {
>                     for (int i = 0; i < cookies.length; i++) {
>                         System.out.println(" - " +
> cookies[i].toExternalForm());
>                          httpClient.getState ().addCookie(cookies[i]);
>                     }
>                 }
>
> Log
>
>
> DEBUG [org.apache.commons.httpclient.HttpClient] enter
> HttpClient.executeMethod(HttpMethod)
> DEBUG [org.apache.commons.httpclient.HttpClient ] enter
> HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState)
> DEBUG [org.apache.commons.httpclient.HttpMethodDirector] Attempt number 1
> to process request
> DEBUG [org.apache.commons.httpclient.HttpConnection ] enter
> HttpConnection.open()
> DEBUG [org.apache.commons.httpclient.HttpConnection] Open connection to
> abc.com:443
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
> HttpMethodBase.execute (HttpState, HttpConnection)
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
> HttpMethodBase.writeRequest(HttpState, HttpConnection)
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
> HttpMethodBase.writeRequestLine (HttpState, HttpConnection)
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
> HttpMethodBase.generateRequestLine(HttpConnection, String, String, String,
> String)
> DEBUG [httpclient.wire.header] >> "GET
> /user/dologin.php?username=hwijono&password=Password1&loginid=hwijono&section=inventory&Content-Length=1500&Referer=https%3A%2F%2Fabc.com%2Fv240%2Fuser%2Fdologin.php&location=https%3A%2F%2Fabc.com%2Fv240%2Fuser%2Fdologin.php&Content-Type=application%2Fx-www-form-urlencoded%3B+charset%3DUTF8&Content-Style-Type=text%2Fcss&User-Agent=Mozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+5.1%3B+en-US%3B+rv%3A1.8.0.4%29+Gecko%2F20060508+Firefox%2F1.5.0.4&Cache-Control=private&pragma=no-cache&Connection=keep-alive
> HTTP/1.1[\r][\n]"
>
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.print(String)
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.write(byte[])
> DEBUG [org.apache.commons.httpclient.HttpConnection ] enter
> HttpConnection.write(byte[], int, int)
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
> HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection)
> DEBUG [org.apache.commons.httpclient.HttpMethodBase ] enter
> HttpMethodBase.addRequestHeaders(HttpState, HttpConnection)
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
> HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection)
> DEBUG [org.apache.commons.httpclient.HttpMethodBase ] enter
> HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection)
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] Adding Host request
> header
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
> HttpMethodBase.addCookieRequestHeader (HttpState, HttpConnection)
> DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.getCookies
> ()
> DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
> CookieSpecBase.match(String, int, String, boolean, Cookie[])
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
> HttpMethodBase.addProxyConnectionHeader(HttpState, HttpConnection)
> DEBUG [httpclient.wire.header] >> "User-Agent: Jakarta
> Commons-HttpClient/3.0.1[\r][\n]"
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.print(String)
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.write(byte[])
> DEBUG [org.apache.commons.httpclient.HttpConnection ] enter
> HttpConnection.write(byte[], int, int)
> DEBUG [httpclient.wire.header] >> "Host: singdev.sentienthealth.com
> [\r][\n]"
>
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.print (String)
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.write(byte[])
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.write(byte[], int, int)
> DEBUG [org.apache.commons.httpclient.HttpConnection ] enter
> HttpConnection.writeLine()
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.write(byte[])
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.write(byte[], int, int)
> DEBUG [httpclient.wire.header] >> "[\r][\n]"
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.flushRequestOutputStream()
> DEBUG [org.apache.commons.httpclient.HttpMethodBase ] enter
> HttpMethodBase.readResponse(HttpState, HttpConnection)
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
> HttpMethodBase.readStatusLine(HttpState, HttpConnection)
> DEBUG [org.apache.commons.httpclient.HttpConnection ] enter
> HttpConnection.readLine()
> DEBUG [org.apache.commons.httpclient.HttpParser] enter HttpParser.readLine(InputStream,
> String)
> DEBUG [org.apache.commons.httpclient.HttpParser] enter
> HttpParser.readRawLine()
> DEBUG [ httpclient.wire.header] << "HTTP/1.1 200 OK[\r][\n]"
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
> HttpMethodBase.readResponseHeaders(HttpState,HttpConnection)
> DEBUG [org.apache.commons.httpclient.HttpConnection ] enter
> HttpConnection.getResponseInputStream()
> DEBUG [org.apache.commons.httpclient.HttpParser] enter
> HeaderParser.parseHeaders(InputStream, String)
> DEBUG [org.apache.commons.httpclient.HttpParser] enter HttpParser.readLine(InputStream, String)
> DEBUG [org.apache.commons.httpclient.HttpParser] enter
> HttpParser.readRawLine()
> DEBUG [org.apache.commons.httpclient.HttpParser] enter HttpParser.readLine(InputStream,
> String)
> DEBUG [org.apache.commons.httpclient.HttpParser ] enter
> HttpParser.readRawLine()
> DEBUG [org.apache.commons.httpclient.HttpParser] enter HttpParser.readLine(InputStream,
> String)
> DEBUG [org.apache.commons.httpclient.HttpParser] enter
> HttpParser.readRawLine()
> DEBUG [ org.apache.commons.httpclient.HttpParser] enter
> HttpParser.readLine(InputStream, String)
> DEBUG [org.apache.commons.httpclient.HttpParser] enter
> HttpParser.readRawLine()
> DEBUG [org.apache.commons.httpclient.HttpParser ] enter
> HttpParser.readLine(InputStream, String)
> DEBUG [org.apache.commons.httpclient.HttpParser] enter
> HttpParser.readRawLine()
> DEBUG [org.apache.commons.httpclient.HttpParser] enter HttpParser.readLine(InputStream,
> String)
> DEBUG [org.apache.commons.httpclient.HttpParser] enter
> HttpParser.readRawLine()
> DEBUG [org.apache.commons.httpclient.HttpParser] enter HttpParser.readLine(InputStream,
> String)
> DEBUG [org.apache.commons.httpclient.HttpParser ] enter
> HttpParser.readRawLine()
> DEBUG [org.apache.commons.httpclient.HttpParser] enter HttpParser.readLine(InputStream,
> String)
> DEBUG [org.apache.commons.httpclient.HttpParser] enter
> HttpParser.readRawLine()
> DEBUG [ org.apache.commons.httpclient.HttpParser] enter
> HttpParser.readLine(InputStream, String)
> DEBUG [org.apache.commons.httpclient.HttpParser] enter
> HttpParser.readRawLine()
> DEBUG [httpclient.wire.header] << "Date: Wed, 21 Jun 2006 09:25:26
> GMT[\r][\n]"
>
> DEBUG [httpclient.wire.header] << "Server: Apache/2.0.52 (Red
> Hat)[\r][\n]"
> DEBUG [httpclient.wire.header] << "X-Powered-By: PHP/4.4.0[\r][\n]"
> DEBUG [httpclient.wire.header] << "Set-Cookie:
> swpcookie=hwijono_bba3fbf67c33d39c289e014b46f88a49; path=/[\r][\n]"
> DEBUG [httpclient.wire.header] << "Set-Cookie: pwdexp=deleted;
> expires=Tue, 21 Jun 2005 09:25:25 GMT; path=/[\r][\n]"
>
> DEBUG [httpclient.wire.header] << "Content-Length: 780[\r][\n]"
> DEBUG [httpclient.wire.header] << "Connection: close[\r][\n]"
> DEBUG [httpclient.wire.header] << "Content-Type: text/html;
> charset=utf-8[\r][\n]"
> DEBUG [org.apache.commons.httpclient.HttpMethodBase ] enter
> HttpMethodBase.processResponseHeaders(HttpState, HttpConnection)
> DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
> CookieSpecBase.parse(String, port, path, boolean, String)
> DEBUG [org.apache.commons.httpclient.cookie.CookieSpec ] enter
> CookieSpecBase.parse(String, port, path, boolean, Header)
> DEBUG [org.apache.commons.httpclient.HeaderElement] enter
> HeaderElement.parseElements(char[])
> DEBUG [org.apache.commons.httpclient.Cookie] enter Cookie(String, String,
> String, String, Date, boolean)
> DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
> RFC2109Spec.validate(String, int, String, boolean, Cookie)
> DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
> CookieSpecBase.validate(String, port, path, boolean, Cookie)
> DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.addCookie
> (Cookie)
> DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
> RFC2109Spec.formatCookie(Cookie)
> DEBUG [org.apache.commons.httpclient.HttpMethodBase ] Cookie accepted:
> "$Version=0; swpcookie=hwijono_bba3fbf67c33d39c289e014b46f88a49; $Path=/"
>
> DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
> CookieSpecBase.parse(String, port, path, boolean, String)
> DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
> CookieSpecBase.parse(String, port, path, boolean, Header)
> DEBUG [org.apache.commons.httpclient.Cookie] enter Cookie(String, String,
> String, String, Date, boolean)
> DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
> RFC2109Spec.validate(String, int, String, boolean, Cookie)
> DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
> CookieSpecBase.validate(String, port, path, boolean, Cookie)
> DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.addCookie
> (Cookie)
> DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
> RFC2109Spec.formatCookie(Cookie)
> DEBUG [org.apache.commons.httpclient.HttpMethodBase ] Cookie accepted:
> "$Version=0; pwdexp=deleted; $Path=/"
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
> HttpMethodBase.readResponseBody(HttpState, HttpConnection)
> DEBUG [org.apache.commons.httpclient.HttpMethodBase ] enter
> HttpMethodBase.readResponseBody(HttpConnection)
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.getResponseInputStream()
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
> HttpMethodBase.canResponseHaveBody (int)
>  *** STATUS CODE 200
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
> <!--"http://www.w3.org/TR/html4/strict.dtd"-->
> <html>
> <head>
> <title></title>
>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> <link rel=STYLESHEET type="text/css" href=" https://abc.com/lib/en.css"
> title="medtrac">
>
> <script language="javascript">function submitform() {
> document.frmdologin.submit(); }</script></head>
> <body onload="submitform();"><center><b>Logging in...please
> wait</b></center>
>    <form name="frmdologin" method="post" action="https://abc.com/v240/inventory/index.php
> ">
>
>       <input type="hidden" name="message" value="Your browser is not
> accepting the login cookie.  Please enable cookies in your browser.">
>    </form>
> </body>
>
> </html>
> DEBUG [org.apache.commons.httpclient.HttpMethodBase] Should close
> connection in response to directive: close
> DEBUG [org.apache.commons.httpclient.HttpConnection ] enter
> HttpConnection.close()
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.closeSockedAndStreams()
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.releaseConnection ()
> DEBUG [org.apache.commons.httpclient.HttpConnection] Releasing connection
> back to connection manager.
> COOKIE 1
>
> DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.getCookies
> ()
> DEBUG [org.apache.commons.httpclient.cookie.CookieSpec ] enter
> CookieSpecBase.formatCookie(Cookie)
>  - swpcookie=hwijono_bba3fbf67c33d39c289e014b46f88a49
>
> DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.addCookie
> (Cookie)
>  INFO [org.apache.jk.core.MsgContext ] Response already committed
>



-- 
Henry Wijono <:]]><
+65-9337-8373

Re: Cookie and Post Issue..

Posted by Henry Wijono <hw...@gmail.com>.
Hello Roland,

Thank you for the link. Yes, i read it. Though not understanding a 100%, it
gives me a good idea of how it should interact.

A question though.. this cookie from the output.. Status Code is 200. i
don't see a redirection status code. Is that something a server will respond
automatically with 303 or 307 status?

At first page, the site goes to dologin.php then it will go to
user.phpbefore going to the actual report. That's why I am confused
whether there's
some steps i am missing?
I tried post then get, get and post, get and get. It's still giving disable
cookie in browser. Though I can see the cookies are being passed between get
and post. Thanks for your inputs...

swpcookie=hwijono_bba3fbf67c33d39c289e014b46f88a49

the code:

GetMethod method = new GetMethod(urlA);
                NameValuePair[] putData = {
                    new NameValuePair("username", username),
                    new NameValuePair("password", password),
                    new NameValuePair("loginid", username),
                    new NameValuePair("section", "inventory"),
                    new NameValuePair("Content-Length", "1500"),
                    new NameValuePair("Referer", urlA),
                    new NameValuePair("location", urlA),
                    //new NameValuePair("method", "post"),
                    //new NameValuePair("swpcookie", "ABC"),
                    new NameValuePair("Content-Type",
"application/x-www-form-urlencoded; charset=UTF8"),
                    new NameValuePair("Content-Style-Type", "text/css"),
                    new NameValuePair("User-Agent", "Mozilla/5.0 (Windows;
U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4" ),
                    new NameValuePair("Cache-Control", "private"),
                    new NameValuePair("pragma", "no-cache"),
                    new NameValuePair("Connection",
"keep-alive")
                };
                    // POST
                    //method.setRequestBody(putData);
                    // GET
                    method.setQueryString(putData);

                    //write out the request headers
                    System.out.println("*** Request ***");
                    System.out.println("Request Follow Redirects: " +
method.getFollowRedirects());
                    System.out.println("Request URI: " + method.getURI());
                    System.out.println("Request Path: " + method.getPath());
                    System.out.println("Request Query: " +
method.getQueryString());
                    Header[] requestHeaders1 = method.getRequestHeaders();
                    for (int i=0; i < requestHeaders1.length; i++){
                        System.out.print("Request Headers: " +
requestHeaders1[i]);
                    }

                    //write out the response headers
                    System.out.println("*** Response ***");
                    System.out.println("Status Line: " +
method.getStatusLine());
                    Header[] responseHeaders1 = method.getResponseHeaders();
                    for (int i=0; i<responseHeaders1.length; i++){
                        System.out.print(responseHeaders1[i]);
                    }

                // Execute the method.
                statusCode = httpClient.executeMethod(method);

                System.out.println(" *** STATUS CODE " + statusCode);
                if (statusCode != HttpStatus.SC_OK) {
                    System.err.println("Method failed: " +
method.getStatusLine());
                }

            is = new InputStreamReader(method.getResponseBodyAsStream());
            in = new BufferedReader(is);

            for ( String s; ( s = in.readLine() ) != null; )
                System.out.println( s );

            System.out.println("COOKIE 1 ");

                Cookie[] cookies = httpClient.getState().getCookies();
                if (cookies.length == 0) {
                    System.out.println("None");
                } else {
                    for (int i = 0; i < cookies.length; i++) {
                        System.out.println(" - " +
cookies[i].toExternalForm());
                         httpClient.getState().addCookie(cookies[i]);
                    }
                }

Log

DEBUG [org.apache.commons.httpclient.HttpClient] enter
HttpClient.executeMethod(HttpMethod)
DEBUG [org.apache.commons.httpclient.HttpClient] enter
HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState)
DEBUG [org.apache.commons.httpclient.HttpMethodDirector] Attempt number 1 to
process request
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.open()
DEBUG [org.apache.commons.httpclient.HttpConnection] Open connection to
abc.com:443
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.execute(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.writeRequest(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.writeRequestLine(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.generateRequestLine(HttpConnection, String, String, String,
String)
DEBUG [httpclient.wire.header] >> "GET
/user/dologin.php?username=hwijono&password=Password1&loginid=hwijono&section=inventory&Content-Length=1500&Referer=https%3A%2F%2Fabc.com%2Fv240%2Fuser%2Fdologin.php&location=https%3A%2F%2Fabc.com%2Fv240%2Fuser%2Fdologin.php&Content-Type=application%2Fx-www-form-urlencoded%3B+charset%3DUTF8&Content-Style-Type=text%2Fcss&User-Agent=Mozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+5.1%3B+en-US%3B+rv%3A1.8.0.4%29+Gecko%2F20060508+Firefox%2F1.5.0.4&Cache-Control=private&pragma=no-cache&Connection=keep-alive
HTTP/1.1[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.print(String)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addRequestHeaders(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] Adding Host request
header
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addCookieRequestHeader(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.getCookies()
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.match(String, int, String, boolean, Cookie[])
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.addProxyConnectionHeader(HttpState, HttpConnection)
DEBUG [httpclient.wire.header] >> "User-Agent: Jakarta
Commons-HttpClient/3.0.1[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.print(String)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [httpclient.wire.header] >> "Host: singdev.sentienthealth.com[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.print(String)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.writeLine()
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[])
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.write(byte[], int, int)
DEBUG [httpclient.wire.header] >> "[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.flushRequestOutputStream()
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readResponse(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readStatusLine(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.readLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [httpclient.wire.header] << "HTTP/1.1 200 OK[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readResponseHeaders(HttpState,HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.getResponseInputStream()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HeaderParser.parseHeaders(InputStream, String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readLine(InputStream,
String)
DEBUG [org.apache.commons.httpclient.HttpParser] enter
HttpParser.readRawLine()
DEBUG [httpclient.wire.header] << "Date: Wed, 21 Jun 2006 09:25:26
GMT[\r][\n]"
DEBUG [httpclient.wire.header] << "Server: Apache/2.0.52 (Red Hat)[\r][\n]"
DEBUG [httpclient.wire.header] << "X-Powered-By: PHP/4.4.0[\r][\n]"
DEBUG [httpclient.wire.header] << "Set-Cookie:
swpcookie=hwijono_bba3fbf67c33d39c289e014b46f88a49; path=/[\r][\n]"
DEBUG [httpclient.wire.header] << "Set-Cookie: pwdexp=deleted; expires=Tue,
21 Jun 2005 09:25:25 GMT; path=/[\r][\n]"
DEBUG [httpclient.wire.header] << "Content-Length: 780[\r][\n]"
DEBUG [httpclient.wire.header] << "Connection: close[\r][\n]"
DEBUG [httpclient.wire.header] << "Content-Type: text/html;
charset=utf-8[\r][\n]"
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.processResponseHeaders(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.parse(String, port, path, boolean, String)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.parse(String, port, path, boolean, Header)
DEBUG [org.apache.commons.httpclient.HeaderElement] enter
HeaderElement.parseElements(char[])
DEBUG [org.apache.commons.httpclient.Cookie] enter Cookie(String, String,
String, String, Date, boolean)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.validate(String, int, String, boolean, Cookie)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.validate(String, port, path, boolean, Cookie)
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.addCookie
(Cookie)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.formatCookie(Cookie)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] Cookie accepted:
"$Version=0; swpcookie=hwijono_bba3fbf67c33d39c289e014b46f88a49; $Path=/"
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.parse(String, port, path, boolean, String)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.parse(String, port, path, boolean, Header)
DEBUG [org.apache.commons.httpclient.Cookie] enter Cookie(String, String,
String, String, Date, boolean)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.validate(String, int, String, boolean, Cookie)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.validate(String, port, path, boolean, Cookie)
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.addCookie
(Cookie)
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
RFC2109Spec.formatCookie(Cookie)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] Cookie accepted:
"$Version=0; pwdexp=deleted; $Path=/"
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readResponseBody(HttpState, HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.readResponseBody(HttpConnection)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.getResponseInputStream()
DEBUG [org.apache.commons.httpclient.HttpMethodBase] enter
HttpMethodBase.canResponseHaveBody(int)
 *** STATUS CODE 200
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<!--"http://www.w3.org/TR/html4/strict.dtd"-->
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel=STYLESHEET type="text/css" href="https://abc.com/lib/en.css"
title="medtrac">
<script language="javascript">function submitform() {
document.frmdologin.submit(); }</script></head>
<body onload="submitform();"><center><b>Logging in...please
wait</b></center>
   <form name="frmdologin" method="post" action="
https://abc.com/v240/inventory/index.php">
      <input type="hidden" name="message" value="Your browser is not
accepting the login cookie.  Please enable cookies in your browser.">
   </form>
</body>
</html>
DEBUG [org.apache.commons.httpclient.HttpMethodBase] Should close connection
in response to directive: close
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.close()
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.closeSockedAndStreams()
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.releaseConnection()
DEBUG [org.apache.commons.httpclient.HttpConnection] Releasing connection
back to connection manager.
COOKIE 1
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.getCookies()
DEBUG [org.apache.commons.httpclient.cookie.CookieSpec] enter
CookieSpecBase.formatCookie(Cookie)
 - swpcookie=hwijono_bba3fbf67c33d39c289e014b46f88a49
DEBUG [org.apache.commons.httpclient.HttpState] enter HttpState.addCookie
(Cookie)
 INFO [org.apache.jk.core.MsgContext] Response already committed

Re: Cookie and Post Issue..

Posted by Roland Weber <RO...@de.ibm.com>.
Hello Henry,

have you read the Client HTTP Programming Primer?
http://wiki.apache.org/jakarta-httpclient/ForAbsoluteBeginners

It should help you to sort out cookie problems. Once you've
established the session and performed the login, you should
be able to simply request the page you need.

hope that helps,
  Roland



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org