各位晚上好。已经搜索了一个星期,试图找到一种使用 guzzle 进行连接的方法。curl -v https://go.paytraq.com/api/{APICall}?APIToken={APIToken}&APIKey={APIKey} \ -H "Content-Type:text/xml" \ -d "{RequestBody}"我尝试了所有方法,但不断收到未经授权的访问,并且不确定传递 APIToken 和 APIKey 的最佳方法。我已经从终端使用了上面的内容,效果很好。$client = new \GuzzleHttp\Client(['base_uri'=>'https://go.paytraq.com']); $request = $client->request('GET','/api/clients',['debug'=>true],[ 'headers'=> 'APIToken=XXXXXX&APIKey=XXXX' ]);上面是我的代码的最后一个版本,它给了我以下错误GuzzleHttp\Exception\ClientException客户端错误:GET https://go.paytraq.com/api/clients导致401 Unauthorized响应:未提供 API 密钥或令牌下面是 guzzle 调试 Trying 52.16.7.7:443... * Connected to go.paytraq.com (52.16.7.7) port 443 (#0) * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /usr/local/etc/openssl@1.1/cert.pem CApath: /usr/local/etc/openssl@1.1/certs * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256 * ALPN, server did not agree to a protocol * Server certificate: * subject: CN=go.paytraq.com * start date: Oct 14 00:00:00 2019 GMT * expire date: Nov 14 12:00:00 2020 GMT * subjectAltName: host "go.paytraq.com" matched cert's "go.paytraq.com" * issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon * SSL certificate verify ok. > GET /api/clients HTTP/1.1 Host: go.paytraq.com User-Agent: GuzzleHttp/7 * Mark bundle as not supporting multiuse < HTTP/1.1 401 Unauthorized < Content-Type: text/plain; charset=utf-8 < Date: Sat, 01 Aug 2020 21:03:49 GMT < Request-Time: 1 < Server: nginx/1.4.6 (Ubuntu) < Content-Length: 32 < Connection: keep-alive < * Connection #0 to host go.paytraq.com left intact
1 回答
慕后森
TA贡献1802条经验 获得超5个赞
这应该有效:
$client->request('GET', '/api/clients', ['query' => [
'APIToken' => $APIToken,
'APIKey' => $APIkey]
]);
- 1 回答
- 0 关注
- 83 浏览
添加回答
举报
0/150
提交
取消