How do I do HTTP basic authentication using Guzzle?

前端 未结 8 1270
无人及你
无人及你 2020-12-24 00:11

I want to do basic access authentication using Guzzle and I am very new to programming. I have no clue what to do. I tried to do this using curl but my environment requires

8条回答
  •  礼貌的吻别
    2020-12-24 01:06

    If you use it with symfony, you can also define it in your configuration file (config/packages/eight_points_guzzle.yaml for symfony4 or flex or config.yml for the other version)

    In your configuration file :

    eight_points_guzzle:
        clients:         
            your_service:
                # Write here the host where to do requests
                base_url: "yourURL"
    
                options:
                    timeout: 30
                    auth:
                        - yourLogin     # login
                        - yourPassword # password
                plugin: ~
    

    Then, in your service, controller, etc....

    $client  = $this->getContainer()->get('eight_points_guzzle.client.your_service');
    $response = $client->get('yourRoute');
    

    See : https://packagist.org/packages/eightpoints/guzzle-bundle

提交回复
热议问题