0

我想使用 Java 向解析服务器发送一个 http 请求,这里是请求

curl -X PUT \
-H "X-Parse-Application-Id: value" \
-H "X-Parse-REST-API-Key: value" \
-H "Content-Type: application/json" \
-d '{
"channels": [
"Giants"
]
}' \
https://api.parse.com/1/installations/mrmBZvsErB

为了发送它,我使用 HttpURLConnection 创建了一个请求,我设置了三个像这样的第一个参数

connection.setRequestProperty("Content-Type", "application/json");

但是对于最后一个参数,我不确定如何将其设置为请求?任何帮助将不胜感激。

非常感谢。

4

2 回答 2

2

在此页面上,您可以阅读有关-dparam:的信息"(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. [...]

这个答案应该对你有所帮助。

于 2013-06-12T15:02:33.747 回答
2

这是请求的数据。使用 HttpURLConnection 您只需将该数据写入输出流。这是一个例子:

//Need to set this first
connection.doOutput(true);
String data = "{ \"channels\": [\"Giants\"]}";
connection.getOutputStream().write(data.getBytes(CharSet.forName("UTF-8")));

连接是您的 HttpURLConnection。

于 2013-06-12T15:05:14.370 回答