php cURL + HTTP_POST,不断收到 500 错误。不知道?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2453207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cURL + HTTP_POST, keep getting 500 error. Has no idea?
提问by mysqllearner
Okay, I want to make a HTTP_POST using cURL to a SSL site. I already imported the certificate to my server. This is my code:
好的,我想使用 cURL 对 SSL 站点进行 HTTP_POST。我已经将证书导入到我的服务器。这是我的代码:
$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, FALSE);
curl_setopt($ch, 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;
It keep returned "500". Based on w3schools, 500 means Internal Server Error. Is my server having problem? How to solve/troubleshoot this?
它一直返回“500”。基于 w3schools,500 表示内部服务器错误。我的服务器有问题吗?如何解决/解决这个问题?
回答by Macik
Some servers (especially requested with SSL) returns 500 in cases when some parameters of request is set incorrect.
某些服务器(尤其是使用 SSL 请求)在请求的某些参数设置不正确的情况下返回 500。
To avoid ?500 error? (for example) be sure to:
避免 ?500 错误?(例如)一定要:
- set proper "Referer: " header if needed, with
- 如果需要,设置适当的“Referer:”标题,使用
curl_setopt(CURLOPT_REFERER, 'http://site.com/ref_page');
curl_setopt(CURLOPT_REFERER, 'http://site.com/ref_page');
- set proper "User-Agent: " header, with
- 设置正确的“用户代理:”标头,与
curl_setopt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
回答by Young
$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, FALSE);
curl_setopt($ch, 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'];//as preline
if (curl_error($ch)){
$output .= "\n". curl_error($ch);
}
}
curl_close($ch);
echo $output;
BTW: Make sure that CURL moduel is installed.
顺便说一句:确保安装了 CURL 模块。
回答by Kaltezar
You have something wrong inside your server or the script executed on the server which, maybe, throw an unhandled exception.
您的服务器或服务器上执行的脚本有问题,可能会引发未处理的异常。
You should check the server's access and error logs.
您应该检查服务器的访问和错误日志。

