On Tue, 2007-11-13 at 19:20 +0800, Richard G. Reyes wrote:
> Hi All, Oleg,
>
> Masquerading did not change a thing.
>
> In any case I hope that posting my code can make a difference...
>
>
> Here's my code...
>
Form-urlencoded content generated by HttpClient does seem to match that
generated by the browser
P2=admin&gnkey=0b82&Login=Login
P2=123&Login=Login&gnkey=0b82
Oleg
> --code start--
> import org.apache.commons.httpclient.Cookie;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpVersion;
> import org.apache.commons.httpclient.NameValuePair;
> import org.apache.commons.httpclient.cookie.CookiePolicy;
> import org.apache.commons.httpclient.cookie.CookieSpec;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.methods.PostMethod;
>
>
> /**
> * User: Richard Reyes <richard@voxsant.com>
> * Date: Oct 25, 2007
> * Time: 6:34:18 PM
> */
> public class HttpClientTest {
>
> static final String LOGON_SITE = "192.168.15.18";
> static final int LOGON_PORT = 80;
>
> public static void main(String[] args) throws Exception {
>
> System.setProperty("org.apache.commons.logging.Log",
> "org.apache.commons.logging.impl.SimpleLog");
>
> System.setProperty("org.apache.commons.logging.simplelog.showdatetime",
> "true");
>
> System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire",
>
>
> "debug");
>
> System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient",
>
>
> "debug");
>
> System.out.println("Now executing HttpClientTest.main");
>
> HttpClient client = new HttpClient();
>
> client.getParams().setParameter("http.useragent", "Mozilla/5.0
> (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025
> Firefox/2.0.0.9");
>
>
> client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT,
> "http");
> client.getParams().setCookiePolicy(CookiePolicy.DEFAULT);
> GetMethod authget = new GetMethod("/index.htm");
>
> client.executeMethod(authget);
> System.out.println("Login form get: " +
> authget.getStatusLine().toString());
>
> // System.out.println(authget.getResponseBodyAsString());
> // release any connection resources used by the method
> authget.releaseConnection();
>
> // See if we got any cookies
> CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
> Cookie[] initcookies = cookiespec.match(
> LOGON_SITE, LOGON_PORT, "/", false,
> client.getState().getCookies());
> System.out.println("Initial set of cookies:");
>
> if (initcookies.length == 0) {
> System.out.println("None");
> } else {
> for (int i = 0; i < initcookies.length; i++) {
> System.out.println("- " + initcookies[i].toString());
> }
> }
> System.out.println("1");
> PostMethod authpost = new PostMethod("/dologin.htm");
> // PostMethod authpost = new PostMethod("/jsftest/login.jsp");
>
> // Prepare login parameters
> // NameValuePair action = new NameValuePair("action", "login");
> // NameValuePair url = new NameValuePair("url",
> "/jsftest/j_security_check");
> NameValuePair userid = new NameValuePair("P2", "admin");
> NameValuePair password = new NameValuePair("gnkey", "0b82");
> NameValuePair login = new NameValuePair("Login", "Login");
>
> System.out.println("2");
>
> authpost.setRequestBody(
> new NameValuePair[]{userid, password, login });
>
>
> authpost.addRequestHeader("Accept","text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
> authpost.addRequestHeader("Accept-Language","en-us,en;q=0.5");
> authpost.addRequestHeader("Accept-Encoding","gzip,deflate");
>
> authpost.addRequestHeader("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7");
> authpost.addRequestHeader("Keep-Alive","300");
> authpost.addRequestHeader("Connection","keep-alive");
>
> authpost.addRequestHeader("Referer","http://192.168.15.18/index.htm");
>
> client.executeMethod(authpost);
> System.out.println("Login form post: " +
> authpost.getStatusLine().toString());
> authpost.releaseConnection();
> // See if we got any cookies
> // The only way of telling whether logon succeeded is
> // by finding a session cookie
> Cookie[] logoncookies = cookiespec.match(
> LOGON_SITE, LOGON_PORT, "/", false,
> client.getState().getCookies());
> System.out.println("Logon cookies:");
> if (logoncookies.length == 0) {
> System.out.println("None");
> } else {
> for (int i = 0; i < logoncookies.length; i++) {
> System.out.println("- " + logoncookies[i].toString());
> }
> }
>
> int statuscode = authpost.getStatusCode();
>
> System.out.println("statuscode: " + statuscode);
>
>
>
> }
> }
> --code end--
>
>
> Here's the output...
> --output start--
> D:\java\bin\java -Didea.launcher.port=7535
> "-Didea.launcher.bin.path=C:\Program Files\JetBrains\IntelliJ IDEA
> 7.0.1\bin" -Dfile.encoding=windows-1252 -classpath
> "D:\java\jre\lib\charsets.jar;D:\java\jre\lib\deploy.jar;D:\java\jre\lib\javaws.jar;D:\java\jre\lib\jce.jar;D:\java\jre\lib\jsse.jar;D:\java\jre\lib\plugin.jar;D:\java\jre\lib\rt.jar;D:\java\jre\lib\ext\dnsns.jar;D:\java\jre\lib\ext\localedata.jar;D:\java\jre\lib\ext\sunjce_provider.jar;D:\java\jre\lib\ext\sunpkcs11.jar;D:\httpclienttest\out\production\httpclienttest;D:\commons-httpclient-3.1\commons-httpclient-3.1.jar;D:\httpclienttest\lib\commons-logging.jar;D:\httpclienttest\lib\spring.jar;D:\commons-codec-1.3\commons-codec-1.3.jar;C:\Program
>
>
> Files\JetBrains\IntelliJ IDEA 7.0.1\lib\idea_rt.jar"
> com.intellij.rt.execution.application.AppMain HttpClientTest
> Now executing HttpClientTest.main
> 2007/11/13 18:58:55:031 CST [DEBUG] HttpClient - Java version: 1.5.0_11
> 2007/11/13 18:58:55:031 CST [DEBUG] HttpClient - Java vendor: Sun
> Microsystems Inc.
> 2007/11/13 18:58:55:031 CST [DEBUG] HttpClient - Java class path:
> D:\java\jre\lib\charsets.jar;D:\java\jre\lib\deploy.jar;D:\java\jre\lib\javaws.jar;D:\java\jre\lib\jce.jar;D:\java\jre\lib\jsse.jar;D:\java\jre\lib\plugin.jar;D:\java\jre\lib\rt.jar;D:\java\jre\lib\ext\dnsns.jar;D:\java\jre\lib\ext\localedata.jar;D:\java\jre\lib\ext\sunjce_provider.jar;D:\java\jre\lib\ext\sunpkcs11.jar;D:\httpclienttest\out\production\httpclienttest;D:\commons-httpclient-3.1\commons-httpclient-3.1.jar;D:\httpclienttest\lib\commons-logging.jar;D:\httpclienttest\lib\spring.jar;D:\commons-codec-1.3\commons-codec-1.3.jar;C:\Program
>
>
> Files\JetBrains\IntelliJ IDEA 7.0.1\lib\idea_rt.jar
> 2007/11/13 18:58:55:046 CST [DEBUG] HttpClient - Operating system name:
> Windows XP
> 2007/11/13 18:58:55:046 CST [DEBUG] HttpClient - Operating system
> architecture: x86
> 2007/11/13 18:58:55:046 CST [DEBUG] HttpClient - Operating system
> version: 5.1
> 2007/11/13 18:58:55:437 CST [DEBUG] HttpClient - SUN 1.5: SUN (DSA
> key/parameter generation; DSA signing; SHA-1, MD5 digests; SecureRandom;
> X.509 certificates; JKS keystore; PKIX CertPathValidator; PKIX
> CertPathBuilder; LDAP, Collection CertStores)
> 2007/11/13 18:58:55:437 CST [DEBUG] HttpClient - SunRsaSign 1.5: Sun RSA
> signature provider
> 2007/11/13 18:58:55:437 CST [DEBUG] HttpClient - SunJSSE 1.5: Sun JSSE
> provider(PKCS12, SunX509 key/trust factories, SSLv3, TLSv1)
> 2007/11/13 18:58:55:453 CST [DEBUG] HttpClient - SunJCE 1.5: SunJCE
> Provider (implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2,
> PBE, Diffie-Hellman, HMAC)
> 2007/11/13 18:58:55:453 CST [DEBUG] HttpClient - SunJGSS 1.0: Sun
> (Kerberos v5)
> 2007/11/13 18:58:55:453 CST [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/13 18:58:55:468 CST [DEBUG] DefaultHttpParams - Set parameter
> http.useragent = Jakarta Commons-HttpClient/3.1
> 2007/11/13 18:58:55:468 CST [DEBUG] DefaultHttpParams - Set parameter
> http.protocol.version = HTTP/1.1
> 2007/11/13 18:58:55:484 CST [DEBUG] DefaultHttpParams - Set parameter
> http.connection-manager.class = class
> org.apache.commons.httpclient.SimpleHttpConnectionManager
> 2007/11/13 18:58:55:484 CST [DEBUG] DefaultHttpParams - Set parameter
> http.protocol.cookie-policy = default
> 2007/11/13 18:58:55:484 CST [DEBUG] DefaultHttpParams - Set parameter
> http.protocol.element-charset = US-ASCII
> 2007/11/13 18:58:55:484 CST [DEBUG] DefaultHttpParams - Set parameter
> http.protocol.content-charset = ISO-8859-1
> 2007/11/13 18:58:55:484 CST [DEBUG] DefaultHttpParams - Set parameter
> http.method.retry-handler =
> org.apache.commons.httpclient.DefaultHttpMethodRetryHandler@c40c80
> 2007/11/13 18:58:55:484 CST [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/13 18:58:55:500 CST [DEBUG] DefaultHttpParams - Set parameter
> http.useragent = Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
> rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9
> 2007/11/13 18:58:55:515 CST [DEBUG] DefaultHttpParams - Set parameter
> http.protocol.cookie-policy = default
> 2007/11/13 18:58:55:843 CST [DEBUG] HttpConnection - Open connection to
> 192.168.15.18:80
> 2007/11/13 18:58:55:937 CST [DEBUG] header - >> "GET /index.htm
> HTTP/1.1[\r][\n]"
> 2007/11/13 18:58:55:937 CST [DEBUG] HttpMethodBase - Adding Host request
> header
> 2007/11/13 18:58:56:000 CST [DEBUG] header - >> "User-Agent: Mozilla/5.0
> (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025
> Firefox/2.0.0.9[\r][\n]"
> 2007/11/13 18:58:56:000 CST [DEBUG] header - >> "Host:
> 192.168.15.18[\r][\n]"
> 2007/11/13 18:58:56:000 CST [DEBUG] header - >> "[\r][\n]"
> 2007/11/13 18:58:56:000 CST [DEBUG] header - << "HTTP/1.1 200 OK[\r][\n]"
> 2007/11/13 18:58:56:000 CST [DEBUG] header - << "HTTP/1.1 200 OK[\r][\n]"
> 2007/11/13 18:58:56:000 CST [DEBUG] header - << "Content-Type:
> text/html; charset=iso-8859-1[\r][\n]"
> 2007/11/13 18:58:56:000 CST [DEBUG] header - << "Server:
> Grandstream/1.10[\r][\n]"
> 2007/11/13 18:58:56:000 CST [DEBUG] header - << "[\r][\n]"
> 2007/11/13 18:58:56:000 CST [INFO] HttpMethodBase - Response content
> length is not known
> 2007/11/13 18:58:56:109 CST [DEBUG] HttpMethodBase - Force-close
> connection: true
> Login form get: HTTP/1.1 200 OK
> 2007/11/13 18:58:56:109 CST [DEBUG] HttpMethodBase - Should force-close
> connection.
> 2007/11/13 18:58:56:109 CST [DEBUG] HttpConnection - Releasing
> connection back to connection manager.
> Initial set of cookies:
> None
> 1
> 2
> 2007/11/13 18:58:56:125 CST [DEBUG] HttpConnection - Open connection to
> 192.168.15.18:80
> 2007/11/13 18:58:56:203 CST [DEBUG] header - >> "POST /dologin.htm
> HTTP/1.1[\r][\n]"
> 2007/11/13 18:58:56:203 CST [DEBUG] HttpMethodBase - Adding Host request
> header
> 2007/11/13 18:58:56:203 CST [DEBUG] HttpMethodBase - Default charset
> used: ISO-8859-1
> 2007/11/13 18:58:56:203 CST [DEBUG] HttpMethodBase - Default charset
> used: ISO-8859-1
> 2007/11/13 18:58:56:218 CST [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/13 18:58:56:218 CST [DEBUG] header - >> "Accept-Language:
> en-us,en;q=0.5[\r][\n]"
> 2007/11/13 18:58:56:218 CST [DEBUG] header - >> "Accept-Encoding:
> gzip,deflate[\r][\n]"
> 2007/11/13 18:58:56:218 CST [DEBUG] header - >> "Accept-Charset:
> ISO-8859-1,utf-8;q=0.7,*;q=0.7[\r][\n]"
> 2007/11/13 18:58:56:218 CST [DEBUG] header - >> "Keep-Alive: 300[\r][\n]"
> 2007/11/13 18:58:56:218 CST [DEBUG] header - >> "Connection:
> keep-alive[\r][\n]"
> 2007/11/13 18:58:56:218 CST [DEBUG] header - >> "Referer:
> http://192.168.15.18/index.htm[\r][\n]"
> 2007/11/13 18:58:56:218 CST [DEBUG] header - >> "User-Agent: Mozilla/5.0
> (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025
> Firefox/2.0.0.9[\r][\n]"
> 2007/11/13 18:58:56:218 CST [DEBUG] header - >> "Host:
> 192.168.15.18[\r][\n]"
> 2007/11/13 18:58:56:218 CST [DEBUG] header - >> "Content-Length: 31[\r][\n]"
> 2007/11/13 18:58:56:218 CST [DEBUG] header - >> "Content-Type:
> application/x-www-form-urlencoded[\r][\n]"
> 2007/11/13 18:58:56:234 CST [DEBUG] header - >> "[\r][\n]"
> 2007/11/13 18:58:56:234 CST [DEBUG] content - >>
> "P2=admin&gnkey=0b82&Login=Login"
> 2007/11/13 18:58:56:234 CST [DEBUG] EntityEnclosingMethod - Request body
> sent
>
> Process finished with exit code 1
> --output end--
>
> Here are the links to the screen shots of the browser and httpclient
> packets...
>
> httpclient: http://tinypic.com/view.php?pic=8a3artg&s=1
> browser: http://tinypic.com/view.php?pic=86t9i6w&s=1
>
>
> Thanks in advance.
> Richard
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
|