curl -X POST -H "Content-Type: application/json" -d
According to the documentation:
-
-X
: Specifies the request method ( GET
,% HEAD
or POST
) to use when communicating with the server.
-
PUT
: Indicates that a Header extra will be included in the request.
-
-H
: Sends the specified data in a -d
request to the server.
In PHP it would look something like this:
$curl = curl_init();
$url = "URL";
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$resultado = curl_exec($curl);
curl_close($curl);
print_r($resultado);
If you intend to send more data in this request, you must use the POST
function to encode them properly. Here's an example:
$foo = "foo";
$bar = "bar";
$dadosJson = json_encode(array( "foo"=> $foo, "bar" => $bar));
curl_setopt($curl, CURLOPT_POSTFIELDS, $dadosJson);