I'm calling a URL of this kind:
Accessing through the browser URL I get the correct result. And the same when using the command line with curl, it retrieves the correct information:
C:\>curl "http://localhost:9910/boxreload/check?name=alvaro&test=true" -i
HTTP/1.1 200 OK
Content-type: application/json; charset=UTF-8
Content-length: 203
Server: Restlet-Framework/2.3.3
Accept-ranges: bytes
Date: Fri, 22 Jan 2016 18:01:30 GMT
{"restul": "true"}
But when doing it with PHP it never comes back from the curl_exec and the server times out after 30 seconds.
$stringData = http_build_query($data);
$url = sprintf("%s?%s", $url, $stringData);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;',
'Content-Length: ' . strlen($stringData))
);
// $url is "'http://localhost:9910/boxreload/check?name=alvaro&test=true'"
curl_setopt($curl, CURLOPT_URL, $url );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
//never comes back from this call (server times out)
$curl_response = curl_exec($curl);
if(curl_response === FALSE){
echo "error en CURL";
echo curl_error($curl);
}
curl_close($curl);
//never reaches this point
print_r($curl_response);
Why is it? Am I doing anything wrong?
echonothing. What did you expect?curl_exec... never coming back. I don't echo anything in this example because it is not necessary for my question.curl_setopt($curl, CURLOPT_PORT, 9910);print_rin the last line to echo and are you sure what you're connecting to requires the client to send the'Content-Type: application/json' and 'Content-Length: nnn'headers? Because if they're supposed to be response headers, then don't send those headers as part of the request.