• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Anjali GauravSingh
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your response ....
Please find the code mentioned below:

Anjali

 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22853
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anjali GauravSingh wrote:shud


Use real words please.

wll you please share more advice on this


Put the number in the URL:
 
Anjali GauravSingh
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is the exception thrown. This problem is not fixed yet.

Apreciate your comments in advance

anjali
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Anjali GauravSingh
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your advice but will you please elaborate your suggestion little bit more.
 
Ahsan Habib
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.">
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic