Laravel 5.5 - Guzzle 6 卷曲错误 51
Laravel 5.5 - Guzzle 6 curl error 51
我正在努力将项目从 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,
],
]);
原来我只需要从 6.0.2 升级到 6.3。
我正在努力将项目从 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,
],
]);
原来我只需要从 6.0.2 升级到 6.3。