1

I want to send an HTTP request using Java to the parse server, here is the request

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

To send it I have created a request using HttpURLConnection, I have set the three first params like this

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

But for the last param, I am not sure how to set it to the request?

HoRn
  • 1,458
  • 5
  • 20
  • 25
Morgan
  • 21
  • 3

2 Answers2

2

On this page you can read about -d param: "(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. [...].

This answer should help you.

Community
  • 1
  • 1
pepuch
  • 6,346
  • 7
  • 51
  • 84
2

That's the data for the request. Using HttpURLConnection you will simply need to write that data to the output stream. Here's an example:

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

Where connection is your HttpURLConnection.

Simeon G
  • 1,188
  • 8
  • 20