Login to website using httpclient

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Login to website using httpclient

Postby chris.schuette » Sat Jan 09, 2010 5:07 pm

Hi,

I have difficulties to log into a website using the Java httpclient class. The login portion of the website looks like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. <form action="http://www.url.com/index.php/cp/login/login?return_url=%2F" method="post">
  2.  
  3. <div class="input">
  4.  
  5. <input id="login-email" name="email" value="a@b.com" type="text">
  6.  
  7. <input id="login-password" name="password" value="" type="password">
  8.  
  9. <input class="submit" value="Login" type="submit">
  10.  
  11. </form>
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


It tried the following code, but I was not successfull:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. HttpPost httpost = new HttpPost("http://www.url.com/index.php/cp/login/login?return_url=");
  3.  
  4. List <NameValuePair> nvps = new ArrayList <NameValuePair>();
  5.  
  6. nvps.add(new BasicNameValuePair("email", "a@b.com"));
  7.  
  8. nvps.add(new BasicNameValuePair("password", "xxxxxx"));
  9.  
  10. httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
  11.  
  12. response = httpclient.execute(httpost);
  13.  
  14. entity = response.getEntity();
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


However I was unsuccessful. I received a 417 error. Can someone point me in the right direction? I would really appreciate this.


Thank you in advance,

Christoph
chris.schuette
Freshman
Freshman
 
Posts: 8
Joined: Tue Jul 14, 2009 10:59 am

Top

Postby jwei512 » Mon Jan 11, 2010 1:03 pm

How you handle the POST call seems fine... how are you defining your httpClient?

Based off the parameters you set for your DefaultHttpClient that might be the problem.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby chris.schuette » Mon Jan 11, 2010 1:06 pm

Hey,

this is solved. The problem lies in a html optimization, that is activated by standard upon creating a httpclient instance, however not supported by the server.

A simple:
httpclient.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);

Does the trick.

Thanks,

Christoph
chris.schuette
Freshman
Freshman
 
Posts: 8
Joined: Tue Jul 14, 2009 10:59 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 8 guests