为什么在使用 curl_exec($curl) 后 $status = 0?

Why does $status = 0 After Using curl_exec($curl)?

我正在尝试使用 DocuSign API 创建一个 recipientView。我正在尝试使用 cURL 库 POST PHP 中的请求,但由于某种原因,在执行我的代码时,下面代码中的行 $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 返回 0:

$url = "http://demo.docusign.net/restapi/v2/accounts/$account_id/envelopes/
        $envelope_id/views/recipient";

$body = array("returnUrl" => "http://www.docusign.com/devcenter",
                "authenticationMethod" => "None", 
                "email" => "$recipient",
                "userName" => "$recipient");

$body_string = json_encode($body);

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Accept: application/json',
    'Content-Type: application/json',
    'Content-Length: '.strlen($body_string),
    'Authorization: Bearer '.$access_token
));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body_string);

$json_response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

echo $status;

$response = json_decode($jason_response, true);
$url = $response["url"];

我正在通过 JSON 发送 POST,我应该得到的响应是 JSON。为什么我的 curl_exec() 失败并使 $status = 0

您没有包括身份验证 header。对 API 的每次调用都需要进行身份验证。

Docs about Authentication options

curl_exec出现错误时,curl_getinfo($curl, CURLINFO_HTTP_CODE);的结果将为零。由于您发现 curl_error 返回了以下内容:

Failed to connect to demo.docusign.net port 80: Connection refused

结果为零。

您必须找出 DocuSign 拒绝您连接的原因(查看他们的 API 文档)。一旦你弄清楚并修复它,你应该得到一个正确的 JSON 结果以及一个有效的 HTTP 状态代码。

您的错误消息的原因

Failed to connect to demo.docusign.net port 80: Connection refused

是否您正在尝试连接到 HTTP 端口 80 但 docusign.net 仅侦听 HTTPS 端口 443。

将 API URL 从 http:// 更改为 https:// 并且您应该被设置并且 curl_getinfo() 将 return 正确的值作为嗯