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

后端 未结 2 1825
广开言路
广开言路 2020-12-30 02:05

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

相关标签:
2条回答
  • 2020-12-30 02:27

    EDIT: You need to find the exact error message that facebook is sending in the response You can modify your code to get the message from the error stream like so:

    HttpURLConnection httpConn = (HttpURLConnection)connection;
    InputStream is;
    if (httpConn.getResponseCode() >= 400) {
        is = httpConn.getErrorStream();
    } else {
        is = httpConn.getInputStream();
    }
    

    Take a look at how you are passing the user context Here's some information that could help you out:

    Look at the error message behind the 400 response code:

    "Facebook Platform" "invalid_request" "An active access token must be used to query information about the current user*

    You'll find the solution here

    HTTP/1.1 400 Bad Request
    ...
    WWW-Authenticate: OAuth "Facebook Platform" "invalid_request" "An active access token must be used to query information about the current user."
    ...
    
    0 讨论(0)
  • 2020-12-30 02:37

    I finally found the problem. Of course it's my code. One part of the code I didn't post is the value of data. data must contain only name and description but I am passing more than name and description.

    0 讨论(0)
提交回复
热议问题