I have this code in the client side of my application:
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, \"GET\");
curl_setopt($ch, CURLOPT_RETURNT
If you use http PUT
with curl then you have to specify the Content-Length
header. Otherwise it is automatically handled by the curl for both GET
and POST
.
For example if you are posting the following data
with curl with CURLOPT_POSTFIELDS
. Then curl will automatically add the length of the data
with the header.
$data = "name=alex&email=none!";
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
For better understand, run your curl code using verbose mode and you'll see how its handling the requests and responses.
curl_setopt($ch, CURLOPT_VERBOSE, true);