• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simulate POST using HttpURLConnection

 
Ekaterina Galkina
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I need to implement the following task - login into a site (e.g. http://myexample.com) using java. I chose HttpURLConnection. I need to simulate POST request, user name and password are provided.
When I use browser login is successfull, but the code below rises an Exception (java.io.IOException: Server returned HTTP response code: 408 for URL). That means Request timeout. Why? How to avoid it?

BTW, in browser login is successfull, I see the welcome page. But Firebug demonstrates response code 302.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd use a library like HtmlUnit for this. It takes care of all the nitty gritty details of HTTP and HTML forms, including cookies and sessions, so your code doesn't have to.
 
Ekaterina Galkina
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:I'd use a library like HtmlUnit for this. It takes care of all the nitty gritty details of HTTP and HTML forms, including cookies and sessions, so your code doesn't have to.


Thank you. Can anyone provide htmlunit for me? http://sourceforge.net/projects/htmlunit/files/htmlunit/ download seems not working.

Update: Now downloading is enabled. I've got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic