• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Unable to access URL using HttpURLConnection

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using HttpURLCOnnection class to post a data to a url(which is a web service). The webservice accepts data as text/xml.

Following is the code snippet i used:

URL url = new URL("http://xxx.xxx.xx.xx:8080/SampleWebService.svc");
HttpURLConnection conn =(HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","text/xml");
String urlStr="param1="URLEncoder.encode(value1)"¶m2="+URLEncoder.encode(value2)
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(urlStr);
wr.flush();
InputStream in2 = conn.getInputStream();
in2.close();
wr.close();

But when i execute the code, I am getting following error at the line(InputStream in2 = conn.getInputStream()(IMG:style_emoticons/default/wink.gif)

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

Can someone please suggest a solution. Am i missing something here?

Thanks in advance
 
Sheriff
Posts: 22821
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
A related thread. And like that one, this thread is going to the Sockets forum as well.
 
On top of spaghetti all covered in cheese, there was this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic