从卷曲请求到https服务器无响应 [英] No Response getting from Curl Request to https server

查看:74
本文介绍了从卷曲请求到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.

这篇关于从卷曲请求到https服务器无响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆