Note that there are some explanatory texts on larger screens.

plurals
  1. POURLConnection Error - java.io.IOException: Server returned HTTP response code: 400 for URL
    primarykey
    data
    text
    <p>I am trying to connect to a URL from a desktop app, and I get the error indicated in the Title of my question, but when I tried to connect to the same URL from servlet, all works fine. When I load the URL from browser, all works fine. I am using the same code in the servlet. The code was in a library, when it didn't work, I pulled the code out to a class in the current project, yet it didn't work.</p> <p>The URL <a href="https://graph.facebook.com/me" rel="noreferrer">https://graph.facebook.com/me</a>. </p> <p>The Code fragment.</p> <pre><code>public static String post(String urlSpec, String data) throws Exception { URL url = new URL(urlSpec); URLConnection connection = url.openConnection(); connection.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); writer.write(data); writer.flush(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line = ""; StringBuilder builder = new StringBuilder(); while((line = reader.readLine()) != null) { builder.append(line); } return builder.toString(); } </code></pre> <p>I'm a little bit confused here, is there something that is present is a servlet that is not a normal desktop app?</p> <p>Thanks.</p> <p>FULL STACK TRACE</p> <pre><code>Feb 8, 2011 9:54:14 AM com.trinisoftinc.jiraffe.objects.FacebookAlbum create SEVERE: null java.io.IOException: Server returned HTTP response code: 400 for URL: https://graph.facebook.com/me at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1313) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234) at com.jiraffe.helpers.Util.post(Util.java:49) at com.trinisoftinc.jiraffe.objects.FacebookAlbum.create(FacebookAlbum.java:211) at com.trinisoftinc.jiraffe.objects.FacebookAlbum.main(FacebookAlbum.java:261) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload