dongwei2882 2019-01-18 20:35
浏览 38

在symfony 4上guzzle客户端格式错误的网址

I'm working on a symfony 4.2 project and using guzzle client (6.3).

I created a clients.yml and configured my guzzle clients by base_uri.

clients.yml

parameters:
    client_config:
        base_uri: ~
        defaults:
            timeout: '%client_timeout%'
            connect_timeout: '%client_connect_timeout%'
            verify: false

    provider_client_config:
        base_uri: '%provider_url%'
        defaults:
            timeout: '%client_timeout%'
            verify: false
            connect_timeout: '%client_connect_timeout%'
            headers:
                content-type: '%client_content_type%'

services:
    # Default HTTP Client service
    client:
        class: GuzzleHttp\Client
        arguments: ['%client_config%']

    provider_client:
        class: GuzzleHttp\Client
        arguments: ['%provider_client_config%']

And imported my clients.yml into services.yml.

services.yml

# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

imports:
    - { resource: clients.yml }

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
    provider_url: 'endpoint'
    client_content_type: application/json
    client_timeout: 30
    client_connect_timeout: 5

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

    # controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

    # add more service definitions when explicit configuration is needed
    # please note that last definitions always *replace* previous ones

    GuzzleHttp\Client:
        public: true
        autowire: true
        autoconfigure: false

    App\Service\Adapter\Provider:
        class: App\Service\Adapter\Provider
        arguments:
            - '@provider_client'
        public: true
        autowire: true
        autoconfigure: false

When i try to send request from command by adapter, guzzle client returns cURL error 3: malformed.

Command:

class TestCommand extends Command
{
    protected static $defaultName = 'command:command';

    /**
     * @var Client
     */
    private $client;

    public function __construct(Client $client)
    {
        $this->client = $client;

        parent::__construct();
    }

    protected function configure()
    {
        $this
            ->setDescription('test.')
            ->setHelp('test.');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $lol = new ProviderOne($this->client);
    }
}

Adapter:

 $response = $this->client->request('GET', '');

Where is wrong of my configuration, i can not figure out it.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度