[英]PHP cURL function for GET method
I am trying to write a cURL function for GET method. 我正在尝试为GET方法编写一个cURL函数。 Following is the code:
以下是代码:
$ch = curl_init();
$token="43e6c623dda8f35dXXXXec57d58e91154a";
$code="13200XX";
$url="https://test.delhivery.com/c/api/pin-codes/json/?token=".$token."&filter_codes=".$code;
echo $url;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return = curl_exec ($ch);
curl_close ($ch);
echo $return;
When I echo the above $url
, I am getting the desired output but where I am wrong to write a cURL function, because when I am placing the same URL token in the cURL function I am getting blank page. 当我赞同上述
$url
,我得到了想要的输出,但在那里我错写的卷曲功能,因为当我把相同的URL令牌卷曲功能我得到的空白页。
Please help me. 请帮我。
There may be plenty of reasons why it is not working. 可能有很多原因导致它无法正常工作。
Before doing all these steps below check if url in browser or postman or any other client returns correct response and also set error_reporting(E_ALL)
and ini_set('display_errors', 1)
在执行以下所有步骤之前,请检查浏览器或邮递员或任何其他客户端中的url是否返回正确的响应,并设置
error_reporting(E_ALL)
和ini_set('display_errors', 1)
echo curl_error($ch);
echo curl_error($ch);
的输出是什么echo curl_error($ch);
if it's empty then go to next steps curl_setopt()
CURLOPT_USERAGENT
some servers maybe set to deny connection if there is no browser header curl_setopt()
CURLOPT_USERAGENT
添加浏览器标头,如果没有浏览器标头,则某些服务器可能设置为拒绝连接 curl_setop(
) CURLOPT_COOKIEFILE
curl_setop(
) CURLOPT_COOKIEFILE
接受curl中的cookie CURLOPT_SSL_VERIFYPEER
and CURLOPT_SSL_VERIFYHOST
options to 0 CURLOPT_SSL_VERIFYPEER
和CURLOPT_SSL_VERIFYHOST
选项设置为0的原因
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.