<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>405 HTTP method GET is not supported by this URL</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: HTTP method GET is not supported by this URL</h1>
</body></html>
String data = "{\"data\": [{\"text\": \"I love Titanic.\"}, {\"text\": \"I hate Titanic.\"}]}";
URL url = new URL("http://www.sentiment140.com/api/bulkClassifyJson?appid=me@gmail.com");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
// write the request body
connection.getOutputStream().write(data.getBytes("UTF8"));
// get the response and read it
InputStream in = connection.getInputStream();
# 1 楼答案
你确定你在发帖吗?上面的URL看起来像GET
# 2 楼答案
根据API documentation,应该将JSON数据作为
POST
方法的请求体传递,而不是作为URL参数传递所以它应该是这样的: