Home:ALL Converter>Server returned HTTP response code: 400 for URL:

Server returned HTTP response code: 400 for URL:

Ask Time:2016-08-03T22:30:35         Author:Zupermi

Json Formatter

I get this error:
java.io.IOException: Server returned HTTP response code: 400 for URL: https://graph.facebook.com/search?q=java&type=post at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source) at java.net.URL.openStream(Unknown Source) at Main.main(Main.java:19)

for this code:

import java.io.BufferedReader;
import java.io.IOException;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;

import org.json.JSONObject;
import javax.json.*;



public class Main {
    public static void main(String[] args) {
          try {
              URL url = new URL("https://graph.facebook.com/search?q=java&type=post");
              InputStream is = url.openStream();
              JsonReader rdr = Json.createReader(is);        
              JsonObject obj = rdr.readObject();
              JsonArray results = obj.getJsonArray("data");
              for (JsonObject result : results.getValuesAs(JsonObject.class)) {
                  System.out.print(result.getJsonObject("from").getString("name"));
                  System.out.print(": ");
                  System.out.println(result.getString("message", ""));
                  System.out.println("-----------");
              }
          } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

and i don't understand why?

Author:Zupermi,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/38746503/server-returned-http-response-code-400-for-url
yy