从卷曲请求到https服务器无响应
问题描述:
我正在向服务器创建一个PHP curl请求,并且期望响应中有一些字符串,但没有生成响应,这可能是什么原因?
I am creating a PHP curl request to server and expecting some string in response but no response generating , What may be the reason for that?
下面是Curl相同的代码:
Below is the Curl code for the same:
$fields = array("username"=> 'xxx',"domain"=> 'xxx',"password" => 'xxx');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://host:8090/add-user");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $usr.':'.$pass);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
if(!$result=curl_exec($ch)){
trigger_error(curl_error($ch));
}
curl_close($ch);
var_dump($result);
以下是相同的命令行请求:
Below is equivalent command line request for the same:
curl --data 'username=xxx&domain=xxx&password=xxx' https://host:8090/add-user -k -v -u 'usr:pass'
我在做什么错了?
答
您应该首先尝试使用 curl_setopt($ ch,CURLOPT_VERBOSE,$ file_handler);
其中 $ file_handler
= fopen('somefile.log','a')
。因此,您将看到 cURL 的确切功能以及失败的地方。
You should first try to use curl_setopt($ch, CURLOPT_VERBOSE, $file_handler);
where $file_handler
= fopen('somefile.log', 'a')
. Thus you will see what exactly cURL does, and where it fails.