aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Simulate POST using HttpURLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Simulate POST using HttpURLConnection" Watch "Simulate POST using HttpURLConnection" New topic
Author

Simulate POST using HttpURLConnection

Ekaterina Galkina
Greenhorn

Joined: Sep 14, 2010
Posts: 15
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
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
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

Joined: Sep 14, 2010
Posts: 15
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simulate POST using HttpURLConnection