【问题标题】:Laravel 5.5 - Guzzle 6 curl error 51Laravel 5.5 - Guzzle 6 卷曲错误 51
【发布时间】:2018-04-27 20:59:17
【问题描述】:

我正在将一个项目从 Laravel 5.2 升级到 5.5,因此,Guzzle 正在从 5 更新到 6。我正在向外部 API 发出 curl 请求,但我无法获得证书以使用新的结构体。我不断收到 cURL 错误 51。

Guzzle 5 代码

$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,
  ],
]);

【问题讨论】:

    标签: php laravel curl laravel-5.5 guzzle6


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-02
      • 2023-03-10
      • 2020-04-25
      • 1970-01-01
      • 2015-11-02
      • 2018-11-26
      • 1970-01-01
      相关资源
      最近更新 更多