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 Unable to access URL using HttpURLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Unable to access URL using HttpURLConnection" Watch "Unable to access URL using HttpURLConnection" New topic
Author

Unable to access URL using HttpURLConnection

chanveil Kiji
Greenhorn

Joined: Dec 30, 2010
Posts: 15
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
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

A related thread. And like that one, this thread is going to the Sockets forum as well.


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: Unable to access URL using HttpURLConnection