-1
如何構建HTTP POST請求的URL?如何構建HTTP POST請求的URL?
如何構建HTTP POST請求的URL?如何構建HTTP POST請求的URL?
您確定您正在POST'ing?上述網址看起來像GET。
<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>
作爲每API documentation你應該傳遞JSON數據作爲POST
方法的請求主體,而不是作爲URL參數。
因此,它應該是這個樣子:
String data = "{\"data\": [{\"text\": \"I love Titanic.\"}, {\"text\": \"I hate Titanic.\"}]}";
URL url = new URL("http://www.sentiment140.com/api/[email protected]");
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();
的
可能重複[?如何使一個HTTP POST URL連接(http://stackoverflow.com/questions/18527739/how-to-make -an-HTTP-POST-URL連接) – dharam