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§ion=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