加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – cURL HTTP_POST,不断出现500错误.不知道?

发布时间:2020-12-13 21:36:26 所属栏目:PHP教程 来源:网络整理
导读:好的,我想使用cURL创建HTTP_POST到SSL站点.我已经将证书导入了我的服务器.这是我的代码: $url = "https://www.xxx.xxx";$post = "";# all data that going to send$ch = curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_POST,true)
好的,我想使用cURL创建HTTP_POST到SSL站点.我已经将证书导入了我的服务器.这是我的代码:

$url  = "https://www.xxx.xxx";
$post = "";# all data that going to send

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,CURLOPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0'); 

$exe  = curl_exec($ch);
$getInfo = curl_getinfo($ch);

if ($exe === false) {
    $output = "Error in sending";
    if (curl_error($ch)){
        $output .= "n". curl_error($ch);
    }
} else if($getInfo['http_code'] != 777){
    $output = "No data returned. Error: " . $getInfo['http_code'];
    if (curl_error($ch)){
        $output .= "n". curl_error($ch);
    }
}

curl_close($ch);

echo $output;

它保持返回“500”.基于w3schools,500表示内部服务器错误.我的服务器有问题吗?如何解决/排除故障?

解决方法

某些服务器(特别是SSL请求)在请求的某些参数设置不正确的情况下返回500.

为了避免“500错误”(例如),请务必:

>如果需要,设置适当的“Referer:”标题

curl_setopt(CURLOPT_REFERER,’http://site.com/ref_page’);

>设置正确的“User-Agent:”标题,用

curl_setopt(CURLOPT_USERAGENT,’Mozilla / 4.0(兼容; MSIE 5.01; Windows NT 5.0)’);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读