【问题标题】:Guzzle GET with APIKey and APITokern使用 API Key 和 API Token 进行 Guzzle GET
【发布时间】:2020-08-01 21:34:25
【问题描述】:

大家晚上好。

一直在寻找一个星期来尝试找到一种使用 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

【问题讨论】:

    标签: php laravel curl guzzle


    【解决方案1】:

    这应该可行:

    $client->request('GET', '/api/clients', ['query' => [
          'APIToken' => $APIToken,
          'APIKey' => $APIkey]
    ]);
    

    【讨论】:

      猜你喜欢
      • 2018-04-16
      • 1970-01-01
      • 2014-05-12
      • 2018-06-21
      • 1970-01-01
      • 1970-01-01
      • 2022-01-26
      • 2014-04-27
      • 1970-01-01
      相关资源
      最近更新 更多