How do I do HTTP basic authentication using Guzzle?

前端 未结 8 1391
无人及你
无人及你 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 00:57

    According to what @bourgeois247 said about base64 encoding, the following worked perfectly for me on Guzzle 6:

    $client = new Client();
    $credentials = base64_encode('username:password');
    $response = $client->post('url',
            [
                'headers' => [
                    'Authorization' => 'Basic ' . $credentials,
                ],
            ]);
    

提交回复
热议问题