Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Guzzle中使用ssl验证模拟curl请求_Php_Laravel_Guzzle_Php Curl - Fatal编程技术网

Php 在Guzzle中使用ssl验证模拟curl请求

Php 在Guzzle中使用ssl验证模拟curl请求,php,laravel,guzzle,php-curl,Php,Laravel,Guzzle,Php Curl,在我的laraval项目中,我用Guzzle模拟了下面的卷曲请求。但我从端点收到500个错误响应。但下面的curl请求返回200个成功,并具有预期的输出 $authKey = 'gygyjfdrgrwr334523rf4tgdbdgeg5gd8uiy7ergsetw=='; $options = [ CURLOPT_URL => 'https://sample.com/endpoint' , CURLOPT_POST =>

在我的laraval项目中,我用Guzzle模拟了下面的卷曲请求。但我从端点收到500个错误响应。但下面的curl请求返回200个成功,并具有预期的输出

$authKey = 'gygyjfdrgrwr334523rf4tgdbdgeg5gd8uiy7ergsetw==';
        $options = [
            CURLOPT_URL => 'https://sample.com/endpoint' ,
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => http_build_query([
                "grant_type" => "client_credentials",
                "scope" => "test"
            ]),
            CURLOPT_HTTPHEADER => [
                "Authorization: Basic {$authKey}",
                "Content-Type: application/x-www-form-urlencoded",
            ]
   CURLOPT_RETURNTRANSFER => true,
           CURLOPT_VERBOSE => false,
           CURLOPT_FOLLOWLOCATION => false,
           CURLOPT_SSL_VERIFYHOST => 2,
           CURLOPT_SSL_VERIFYPEER => true,
           CURLOPT_SSLCERT => "/absolute/path/to/cert/file",
           CURLOPT_SSLCERTPASSWD => "passphrase",
        ];
        $ch = curl_init();
        curl_setopt_array($ch, $options);
        $output = curl_exec($ch);
我的Guzzle实现如下

$authKey = 'gygyjfdrgrwr334523rf4tgdbdgeg5gd8uiy7ergsetw==';
$response = $this->client->post(
            'https://sample.com/endpoint',
            [
                'body' => http_build_query([
                    "grant_type" => "client_credentials",
                    "scope" => 'test'
                ]),
                'debug' => false,
                'config' => [
                    'curl' => [
                        CURLOPT_SSL_VERIFYPEER => true,
                        CURLOPT_SSL_VERIFYHOST => 2
                    ]
                ],
                'headers' => [
                    "Authorization: Basic {$authKey}",
                    "Content-Type: application/x-www-form-urlencoded",
                ],
                'cert' => ["/absolute/path/to/cert/file" , "passphrase"]
            ]
        );
下面是调试信息

* Hostname in DNS cache was stale, zapped
*   Trying 10.111.2.18...
* TCP_NODELAY set
* Connected to sample.com (11.222.3.44) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: C=AU; ST=Victoria; L=Melbourne; O=Sample Corporation Limited; OU=Software Engineering Services; CN=sample.com
*  start date: Jun 28 02: 07: 22 2018 GMT
*  expire date: Jun 28 02: 17: 00 2020 GMT
*  subjectAltName: host "sample.com" matched cert's "sample.com"
*  issuer: C=BM; O=QuoVadis Limited; CN=QuoVadis Global SSL ICA G3
*  SSL certificate verify ok.
> POST /application/aa/v1/oauth/token HTTP/1.1
Host: sample.com
User-Agent: GuzzleHttp/6.4.1 curl/7.52.1 PHP/7.2.15
0: Authorization: Basic gygyjfdrgrwr334523rf4tgdbdgeg5gd8uiy7ergsetw==
1: Content-Type: application/x-www-form-urlencoded
Content-Length: 50

* upload completely sent off: 50 out of 50 bytes
< HTTP/1.1 500 Internal Server Error
< Date: Sun,
01 Dec 2019 05: 55: 58 GMT
< Content-Type: application/json
< Content-Length: 0
< Connection: keep-alive
< Access-Control-Allow-Origin: *
< Strict-Transport-Security: max-age=31536000; includeSubDomains;
< 
* Curl_http_done: called premature == 0
* Connection #0 to host sample.com left intact
{
    "message": "Server error: `POST https://sample.com/application/aa/v1/oauth/token` resulted in a `500 Internal Server Error`
*DNS缓存中的主机名已过时,已被清除
*正在尝试10.111.2.18。。。
*TCP_节点集
*已连接到sample.com(11.222.3.44)端口443(#0)
*ALPN,提供http/1.1
*密码选择:全部:!出口:!出口40:!出口56:!阿努尔:!低:!RC4:@强度
*已成功设置证书验证位置:
*CAfile:/etc/ssl/certs/ca-certificates.crt
CApath:/etc/ssl/certs
*使用TLSv1.2/ECDHE-RSA-AES256-SHA384的SSL连接
*ALPN,接受使用http/1.1的服务器
*服务器证书:
*主题:C=AU;ST=维多利亚;L=墨尔本;O=样本有限公司;OU=软件工程服务;CN=sample.com
*开始日期:6月28日02:07:22 2018 GMT
*到期日期:6月28日02:17:00格林威治标准时间2020
*subjectAltName:主机“sample.com”匹配证书的“sample.com”
*发行人:C=BM;O=QuoVadis有限公司;CN=QuoVadis全局SSL ICA G3
*SSL证书验证正常。
>POST/application/aa/v1/oauth/token HTTP/1.1
主持人:sample.com
用户代理:GuzzleHttp/6.4.1 curl/7.52.1 PHP/7.2.15
0:授权:基本GYGYJFDRGRWR33423RF4TGDBGEG5GD8UIY7ERGSETW==
1:内容类型:application/x-www-form-urlencoded
内容长度:50
*上传已完全发送:50个字节中有50个

在Guzzle中模拟curl请求时,我是否知道我做错了什么?

当Guzzle需要绝对路径时,curl是否可能接受PEM证书的相对路径?@Arcesilas它是提到的绝对路径。现在提到了,但没有提到,因此我的问题是。如果将
调试
设置为
true,它会说什么?@Arcesilas我添加了调试信息。谢谢。