Base_uri param不用于GET方法

时间:2017-05-17 08:50:52

标签: symfony guzzle guzzle6 guzzlehttp

使用Guzzle 6我的Symfony项目出了问题。

我的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参数被忽略。

一些想法? 谢谢!

1 个答案:

答案 0 :(得分:0)

Services.yml需要像这样完成

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

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