[英]Laravel 5.5 - Guzzle 6 curl error 51
我正在將項目從Laravel 5.2升級到5.5,因此Guzzle從5升級到了6。我向外部API發出了curl請求,但我無法獲得用於新結構的證書。 我不斷收到cURL錯誤51。
食屍鬼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);
狂飲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,
],
]);
原來我只需要從6.0.2升級到6.3。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.