【问题标题】:Base_uri param not used for GET methodBase_uri 参数不用于 GET 方法
【发布时间】:2017-05-18 16:39:10
【问题描述】:

我的 Symfony 项目使用 Guzzle 6 时遇到问题。

我的 service.yml:

ma_core_api.client:
    class: 'GuzzleHttp\Client'
    arguments:
        - [base_uri: '%ma_core_api_base_url%']

我的客户转储是:

object(GuzzleHttp\Client)[620]
  private 'config' => 
    array (size=8)
      0 => 
        array (size=1)
          'base_uri' => string 'http://dev1.core.mobileangelo.net/app_dev.php/api/' (length=50)
      'handler' => 
        object(GuzzleHttp\HandlerStack)[616]
          private 'handler' => 
            object(Closure)[634]
              ...
          private 'stack' => 
            array (size=4)
              ...
          private 'cached' => null
      'allow_redirects' => 
        array (size=5)
          'max' => int 5
          'protocols' => 
            array (size=2)
              ...
          'strict' => boolean false
          'referer' => boolean false
          'track_redirects' => boolean false
      'http_errors' => boolean true
      'decode_content' => boolean true
      'verify' => boolean true
      'cookies' => boolean false
      'headers' => 
        array (size=1)
          'User-Agent' => string 'GuzzleHttp/6.2.1 curl/7.47.0 PHP/7.0.19-1+deb.sury.org~xenial+1' (length=63)

但是当我执行 GET 方法时,堆栈跟踪就像:

(object(EasyHandle),
 array('errno' => '6', 'error' => 'Could not resolve host: v2', 'url' => 'http://v2/transactions/', 'content_type' => null, 'http_code' => '0', 'header_size' => '0', 'request_size' => '0', 'filetime' => '-1', 'ssl_verify_result' => '0', 'redirect_count' => '0', 'total_time' => '0.004181', 'namelookup_time' => '0', 'connect_time' => '0', 'pretransfer_time' => '0', 'size_upload' => '0', 'size_download' => '0', 'speed_download' => '0', 'speed_upload' => '0', 'download_content_length' => '-1', 'upload_content_length' => '-1', 'starttransfer_time' => '0', 'redirect_time' => '0', 'redirect_url' => '', 'primary_ip' => '', 'certinfo' => array(), 'primary_port' => '0', 'local_ip' => '', 'local_port' => '0')) 

如您所见,我的 base_uri 参数被忽略了。

一些想法? 谢谢!

【问题讨论】:

    标签: symfony guzzle6 guzzle


    【解决方案1】:

    Services.yml 需要这样完成

    services:
        api.client:
            class: 'GuzzleHttp\Client'
            arguments:
                - base_uri: 'http://apache.org'
    

    就这样吧 :) base_url 之前的 - 将它作为数组的索引..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-22
      • 1970-01-01
      相关资源
      最近更新 更多