File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes HttpURLConnection - Server returned HTTP response code: 400 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "HttpURLConnection - Server returned HTTP response code: 400" Watch "HttpURLConnection - Server returned HTTP response code: 400" New topic
Author

HttpURLConnection - Server returned HTTP response code: 400

jebastan soundar
Greenhorn

Joined: Sep 27, 2007
Posts: 1
Hi friends,
I am getting this exception "java.io.IOException: Server returned HTTP response code: 400" while getting InputStream. Whereas, hitting the same URL in IExplorer gave the successful response. Please find below the code. Please help. Thanks.

code :

URL hostURL = new URL("http://www.domain.com/abc?paramters=values");
HttpURLConnection urlcon = (HttpURLConnection) hostURL.openConnection();
urlcon.setRequestMethod("GET");
urlcon.setDoInput(true);
//urlcon.connect(); --tried this one also...same exception
InputStream is=urlcon.getInputStream(); -- exception occurs at this line.


Please help me if anyone knows the answer..
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18986
    
    8

My browsers (both Firefox and Internet Explorer) get a 400 response for that URL too.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

If an IOException occurs while calling getInputStream(), you can call getErrorStream() and, if it does not return null, retrieve the actual error message from it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpURLConnection - Server returned HTTP response code: 400