Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从Curl请求到https服务器没有响应_Php_Curl - Fatal编程技术网

Php 从Curl请求到https服务器没有响应

Php 从Curl请求到https服务器没有响应,php,curl,Php,Curl,我正在向服务器创建一个PHP curl请求,并期望响应中有一些字符串,但没有生成响应,这可能是什么原因 下面是相同的Curl代码: $fields = array("username"=> 'xxx',"domain"=> 'xxx',"password" => 'xxx'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://host:8090/add-user"); curl_setopt($ch, CUR

我正在向服务器创建一个PHP curl请求,并期望响应中有一些字符串,但没有生成响应,这可能是什么原因

下面是相同的Curl代码:

$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);
curl --data 'username=xxx&domain=xxx&password=xxx' https://host:8090/add-user -k -v -u 'usr:pass'
下面是相同的等效命令行请求:

$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);
curl --data 'username=xxx&domain=xxx&password=xxx' https://host:8090/add-user -k -v -u 'usr:pass'

我做错了什么?

您应该首先尝试使用
curl\u setopt($ch,CURLOPT\u VERBOSE,$file\u handler)其中
$file\u handler
=
fopen('somefile.log','a')
。因此,您将看到cURL到底做了什么,以及失败的地方。

如果您将cURL\u error()消息变为var\u dump(),会发生什么?不会得到响应,也不会出现错误谢谢。。实际上,响应是通过头返回的。。使用curl_getinfo($ch,CURLINFO_HTTP_代码);解决了这个问题。