I am trying to read a URL using CURL. When I run this URL in my browser, a file gets downloaded on my system, contents in the file are as below
{"Success":true,"Message":"Success","Response":0.0000}
Now I want to get the contents of this file. So far I have used this –
$send_curl = curl_init($url);
curl_setopt($send_curl, CURLOPT_URL, $url);
curl_setopt($send_curl, CURLOPT_HEADER, false);
curl_setopt($send_curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($send_curl, CURLOPT_POST, TRUE);
curl_setopt($send_curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($send_curl, CURLOPT_HTTPHEADER,array('Accept: application/json', "Content-type: application/json"));
curl_setopt($send_curl, CURLOPT_FAILONERROR, FALSE);
curl_setopt($send_curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($send_curl, CURLOPT_SSL_VERIFYHOST, FALSE);
$json_response = curl_exec($send_curl);
$status = curl_getinfo($send_curl, CURLINFO_HTTP_CODE);
curl_close($send_curl);
$response = json_decode($json_response, true);
But I am not getting proper response. Any idea where I am going wrong ?
After a quick test on a local json url, I found that if you remove this, you will be fine :
curl_setopt($send_curl, CURLOPT_POST, TRUE);I mean, if you are not trying to actually POST. Otherwise, it always threw me a “400 Bad Request” error.
Hope this helps!