PHP Curl 错误 35 - 同行报告不兼容或不受支持的协议(protocol)版本

标签 php linux curl centos7

我正在尝试向外部 API(下面的代码)发出 POST 请求。我设法让 curl 编码在我的本地主机上工作,但是当我转到我的登台服务器时,curl 返回错误 Peer reports incompatible or unsupported protocol version(35)。通过阅读本文,我需要添加错误缓冲区以获取更多调试信息,但文档令人困惑。

然而,当我直接在服务器终端中发出 curl 请求时,我收到了一个成功的连接。这让我非常困惑,因为服务器显然能够发出 curl 请求。

PHP curl 代码

$curl = curl_init();

  curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => json_encode($body),
    CURLOPT_HTTPHEADER => $header,
  ));

  $response = curl_exec($curl);
  $err = curl_error($curl);
  echo "response: " . $response;
  echo "<br><br>error: " . $err;

  curl_close($curl);

服务器 curl 响应 curl https://support.zendesk.com/api/v2/users/create_or_update.json

* About to connect() to support.zendesk.com port 443 (#0)
*   Trying 104.16.51.111...
* Connected to support.zendesk.com (104.16.51.111) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
* Server certificate:
*   subject: CN= support.zendesk.com,O="CloudFlare, Inc.",L=San Francisco,ST=CA,C=US
*   start date: Mar 08 00:00:00 2019 GMT
*   expire date: Mar 08 12:00:00 2020 GMT
*   common name: support.zendesk.com
*   issuer: CN=CloudFlare Inc ECC CA-2,O="CloudFlare, Inc.",L=San Francisco,ST=CA,C=US
> GET /api/v2/users/create_or_update.json HTTP/1.1
> User-Agent: curl/7.29.0
> Host: support.zendesk.com
> Accept: */*
> 
< HTTP/1.1 401 Unauthorized
< Date: Fri, 12 Apr 2019 12:52:28 GMT
< Content-Type: application/json; charset=UTF-8
< Content-Length: 37
< Connection: keep-alive
< Set-Cookie: __cfduid=da0ecd56691c96b9b3dac091df58383d51555073548; expires=Sat, 11-Apr-20 12:52:28 GMT; path=/; domain=.ralphandrussoclientcare.zendesk.com; HttpOnly
< WWW-Authenticate: Basic realm="Web Password"
< Strict-Transport-Security: max-age=31536000;
< Cache-Control: no-cache
< X-Zendesk-Origin-Server: app23.pod17.euw1.zdsys.com
< X-Request-Id: 4c65566eacc82981-DUB
< X-Runtime: 0.032000
< X-Zendesk-Request-Id: 3360f95a861586e6f414
< Set-Cookie: __cfruid=7af98f1cbac97922c1c15b82f7c133c3945a446e-1555073548; path=/; domain=.ralphandrussoclientcare.zendesk.com; HttpOnly
< Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
< Server: cloudflare
< CF-RAY: 4c65566eacc82981-DUB
< 
* Connection #0 to host support.zendesk.com left intact
{"error":"Couldn't authenticate you"}

最佳答案

为了解决这个问题,我使用 https://www.ssllabs.com/ssltest/ 执行了服务器 SSL 测试。它向我展示了哪些协议(protocol)已经打开并在服务器上可用。

从那以后,我遵循了这个问题的答案 TLS 1.2 not working in cURL它告诉我要使用哪个 PHP CURLOPT_SSLVERSION 编号来访问开放协议(protocol)。

因此我必须将以下代码行添加到我的 Curl 数组中

CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2

关于PHP Curl 错误 35 - 同行报告不兼容或不受支持的协议(protocol)版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55651944/

相关文章:

使用 HttpURLConnection 的 Android POST 请求

linux - 如何编译ARM EABI工具链?

linux - PostgreSQL 查询在 LINUX 服务器上执行时间太长

php - CORS 与 Laravel 4

php - Mysql一对多关系。按第二个表中的行数排序

linux - 转换 key :value to CSV file

linux - 如何使用 MOD_XML_CURL 通过 HTTP GET 方法检索 SIP 凭据

c++ - curl 发布空对象

php - Zend 查询大于或等于

php - 查询破坏代码时崩溃