Jump to content

Unable to access URL using HttpURLConnection


Recommended Posts

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)"&param2="+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():)java.io.IOException: Server returned HTTP response code: 400 for URLCan someone please suggest a solution. Am i missing something here?Thanks in advance

Link to post
Share on other sites

This isn't Javascript, it's Java.The HTTP 400 error means "Bad request" so you seem to have sent something wrong to the server. I don't really use Java so I can't help much.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...