cURL request in Laravel

前端 未结 5 1285
梦如初夏
梦如初夏 2021-01-30 23:44

I am struggling to make this cURL request in Laravel

curl -d \'{\"key1\":\"value1\", \"key2\":\"value2\"}\' -H \"Content-Type: application/json\"   -X GET http:/         


        
5条回答
  •  礼貌的吻别
    2021-01-31 00:01

    You have forgotten to add \ before namespace.

    You should write:

    $response = $client->post($endpoint, [
                    \GuzzleHttp\RequestOptions::JSON => ['key1' => $id, 'key2' => 'Test'],
                ]);
    

    Instead of:

    $response = $client->post($endpoint, [
                    GuzzleHttp\RequestOptions::JSON => ['key1' => $id, 'key2' => 'Test'],
                ]);
    

提交回复
热议问题