rest - How to debug a get request in php using curl -
i'm trying make request in php using curl. i'm doing:
$curl = curl_init(); curl_setopt($curl, curlopt_httpauth, curlauth_basic); curl_setopt($curl, curlopt_userpwd, "username:password"); curl_setopt($curl, curlopt_url, $url); curl_setopt($curl, curlopt_returntransfer, 1); $result = curl_exec($curl); curl_close($curl); printf($result);
but $result doesn't print out anything, no success or failure message. i've reached endpoint via postman , in web browser know works. printing out $curl prints: "resource #1" makes me think curl installed on server.
i'm not sure steps take next make things work.
add few more option troubleshooting purposes.
check error response.
if no error, details:
curl_setopt($ch, curlopt_connecttimeout, 10); curl_setopt($ch, curlopt_timeout,10); curl_setopt($ch, curlopt_failonerror,true); curl_setopt($ch, curlopt_encoding,""); curl_setopt($ch, curlopt_verbose, true); curl_setopt($ch, curlinfo_header_out, true); curl_setopt($ch, curlopt_header, true); $data = curl_exec($ch); if (curl_errno($ch)){ $data .= 'retreive base page error: ' . curl_error($ch); } else { $skip = intval(curl_getinfo($ch, curlinfo_header_size)); $head = substr($data,0,$skip); $data = substr($data,$skip); $info = curl_getinfo($ch); $info = var_export($info,true); } echo $head; echo $info;
Comments
Post a Comment