Guzzle not sending PSR-7 POST body correctly

后端 未结 2 805
北恋
北恋 2021-02-08 15:33

It is either not being sent, or not being received correctly. Using curl direct from the command line (using the -d option) or from PHP (using CURLOPT_POSTFIELDS) d

2条回答
  •  天涯浪人
    2021-02-08 16:03

    The GuzzleHttp\Client provides all necessary wrapping.

    $response = $client->post(
        $uri,
        [
            'auth' => [null, 'Bearer ' . $token],
            'form_params' => $parameters,
    ]);
    

    Documentation available Guzzle Request Options

    Edit: However, if your requests are being used within GuzzleHttp\Pool then, you can simply everything into the following:

    $request = new GuzzleHttp\Psr7\Request(
        'POST',
        $uri,
        [
           'Authorization' => 'Bearer ' . $token,
           'Content-Type' => 'application/x-www-form-urlencoded'
    
        ],
        http_build_query($form_params, null, '&')
    );
    

提交回复
热议问题