This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.io.IOException: Server returned HTTP response code: 400  RSS feed

 
Hassam Khan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards,
Hassam


URL hostURL = new URL("https://www.domain.com/abc?paramters=values");

HttpURLConnection urlcon = (HttpURLConnection) hostURL.openConnection();
urlcon.setRequestMethod("GET");
urlcon.setDoOutput(true);
urlcon.setDoInput(true);
urlcon.setUseCaches(false);

BufferedReader inputdata = new BufferedReader(new InputStreamReader(urlcon.getInputStream()));
 
Van Glass
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
400 error code means "bad request". It may be that the url only accepts POST requests or there is something that is not properly URL encoded in your parameters.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!