wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes java.io.IOException: Server returned HTTP response code: 400 for URL: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "java.io.IOException: Server returned HTTP response code: 400 for URL:" Watch "java.io.IOException: Server returned HTTP response code: 400 for URL:" New topic
Author

java.io.IOException: Server returned HTTP response code: 400 for URL:

Anjali GauravSingh
Greenhorn

Joined: Nov 03, 2009
Posts: 29
Hi Java Rancher's,
I am trying to implement SMS application in Java. I am facing an error. No idea How to fix it.

Exception in thread "main" java.io.IOException: Server returned HTTP response code: 400 for URL: http://www.way2sms.com/FirstServletsms?custid=
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245)
at helloworld.SMS.send(SMS.java:99)
at helloworld.SMS.main(SMS.java:125)

Java Result: 1
Appreciate your response on it in advance!!
Cheers,
Anjali


Cheers, Anjali
SCJP 82%, SCWCD 94%, Thinking about SCEA
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The server is returning status code 400, which means it didn't understand your request -- i.e., the data you sent to the server was ill-formed. We can't tell you how to fix it, since you're not showing us any code.


[Jess in Action][AskingGoodQuestions]
Anjali GauravSingh
Greenhorn

Joined: Nov 03, 2009
Posts: 29
Thanks for your response ....
Please find the code mentioned below:

Anjali

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Well, look at line 85 of this listing, where you create a URL:

new URL("http://wwwd.way2sms.com/FirstServletsms?custid=");

That's clearly not a valid URL, and it's exactly the one the error message calls out. You need custid to have a value, right?

Anjali GauravSingh
Greenhorn

Joined: Nov 03, 2009
Posts: 29
Well, I have checked it . but its not solving my issue. Do you have any idea.which url shud come and wll you please share more advice on this
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Anjali GauravSingh wrote:shud

Use real words please.

wll you please share more advice on this

Put the number in the URL:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Anjali GauravSingh
Greenhorn

Joined: Nov 03, 2009
Posts: 29
Below is the exception thrown. This problem is not fixed yet.

Apreciate your comments in advance

anjali
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The stack trace doesn't tell us anything -- the original error message has all the information you need. The URL you're trying to use is not valid; the server doesn't like the inputs you're sending to it. I don't know anything about this servlet or what it expects. You need to learn about it so you can send the correct parameters. I don't think we can help you any more here; you're going to have to go do a little research on the proper way to post to that servlet. In other words, it's not a Java programming problem.
Anjali GauravSingh
Greenhorn

Joined: Nov 03, 2009
Posts: 29
Well, I am still trying to debug the application. Could not find the solution. URL is valid when i execute it from browser. Any advice is appreciable

Regards,
Anjali
Ahsan Habib
Greenhorn

Joined: Sep 17, 2008
Posts: 22
Anjali GauravSingh wrote:Well, I am still trying to debug the application. Could not find the solution. URL is valid when i execute it from browser. Any advice is appreciable

Regards,
Anjali


I had same issue as your's and ONLY work-around I found was to use apache commons http-client. Usng HttpURLConnection, I can not connect several web servers, and I use http-client from commons in that case. Still exploring the root cause of failure.


Ahsan Habib
SCJP5, SCWCD5
Anjali GauravSingh
Greenhorn

Joined: Nov 03, 2009
Posts: 29
Thanks for your advice but will you please elaborate your suggestion little bit more.
Ahsan Habib
Greenhorn

Joined: Sep 17, 2008
Posts: 22
Anjali GauravSingh wrote:Thanks for your advice but will you please elaborate your suggestion little bit more.


You can get lots of example on how to use HttpClient. Here I am attaching one sample code to do so. Hope it helps. You have to write one function (see comments)



Right now I could not explain why HttpURLConnection gets 4xx errors, in spite of adding User-Agent property. I let you know if I find.">
Ikenna Okonkwo
Greenhorn

Joined: Nov 18, 2010
Posts: 2
Hi,

I experienced the same error while writing a similar sms class. After much running around and searching, i eventually found it was the proxy server at my office that was refusing connections.
I suggest you also look at this possibility in your own case.

Cheers!!!


--------------------------
oops! old thread... I didn't look at the dates. Hope my contribution still helps someone though!
lefan zhang
Greenhorn

Joined: Jun 09, 2006
Posts: 2
you may consider that use GET instead of POST and do NOT set Cookie atrribute. or you should check whether the cookie value is null or not.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.io.IOException: Server returned HTTP response code: 400 for URL:
 
Similar Threads
java.io.IOException: Server returned HTTP response code: 400
java.io.IOException: Server returned HTTP response code:500 for URL
HttpURLConnection - Server returned HTTP response code: 400
response code: 400 from google images
Unable to access URL using HttpURLConnection