我正在尝试使用 Java 读取 freebase 查询的结果:
URL url = null;
String inputLine;
try{
url = new URL("https://www.googleapis.com/freebase/v1/mqlread?query={\"id\":\"/en/madonna\", \"name\": null, \"type\":\"/base/popstra/celebrity\",\"/base/popstra/celebrity/friendship\": [{\"participant\": [] }] }");
} catch (MalformedURLException e) {
e.printStackTrace();
}
BufferedReader in;
try {
URLConnection con = url.openConnection();
con.setReadTimeout( 1000 ); //1 second
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
但是,我收到以下错误:
java.io.IOException: Server returned HTTP response code: 400 for URL: https://www.googleapis.com/freebase/v1/mqlread?query={ "id":"/en/madonna", "name": null, "type": "/base/popstra/celebrity","/base/popstra/celebrity/friendship": [{ "participant": [] }] }
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at FreebaseCelebrities.main(FreebaseCelebrities.java:66)
我之前已经这样做了(有其他请求)并且它有效,那么这里有什么问题?