Laravel 5.5 - Guzzle 6卷曲错误51

时间:2017-11-14 19:28:33

标签: php laravel curl laravel-5.5 guzzle6

我正在努力将项目从Laravel 5.2升级到5.5,然后Guzzle正在从5更新到6.我正在向外部API发出curl请求,而我无法使用该证书新结构。我一直得到cURL错误51。

Guzzle 5 Code

$opts = [
  'base_url' => rtrim($this->url, '/') . '/',
  'defaults' => [
    'headers' => [
      'Authorization' => $this->shared_key,
      'Accept' => 'application/json',
    ],
    'connect_timeout' => 5,
    'timeout' => 60,
  ],
];

// if a ca certificate is specified, validate against it
if ($this->ssl_ca_store) {
  // create a temp file containing the cert since curl can only read from a file
  $this->sslCaTempFile = tempnam(sys_get_temp_dir(), 'translator-cert-');
  file_put_contents($this->sslCaTempFile, $this->ssl_ca_store);
  $opts['defaults']['config']['curl'] = [
    CURLOPT_CAINFO => $this->sslCaTempFile,
    CURLOPT_SSL_VERIFYPEER => 2, // validate the peer certificate
    CURLOPT_SSL_VERIFYHOST => 0, // don't validate the hostname in the certificate
  ];
}

// create the client with the options from above
$this->client = new Client($opts);

Guzzle 6代码

$opts = [
  'base_uri' => rtrim($this->url, '/') . '/',
  'headers' => [
    'Authorization' => $this->shared_key,
    'Accept' => 'application/json',
  ],
  'connect_timeout' => 5,
  'timeout' => 60,
];

// if a ca certificate is specified, validate against it
if ($this->ssl_ca_store) {
  // create a temp file containing the cert since curl can only read from a file
  $this->sslCaTempFile = tempnam(sys_get_temp_dir(), 'translator-cert-');
  file_put_contents($this->sslCaTempFile, $this->ssl_ca_store);
  $opts['curl'] = [
    CURLOPT_CAINFO => $this->sslCaTempFile,
    CURLOPT_SSL_VERIFYPEER => 2, // validate the peer certificate
    CURLOPT_SSL_VERIFYHOST => 0, // don't validate the hostname in the certificate
  ];
}

// create the client with the options from above
$this->client = new Client($opts);

编辑:这是它失败的请求:

$response = $this->client->request('get', 'auto-verify', [
  'query' => [
    'type' => $this->type,
    'identifier' => $this->identifier,
  ],
]);

1 个答案:

答案 0 :(得分:0)

原来我只需要从6.0.2升级到6.3。