douzhiling3166 2017-09-24 07:31 采纳率: 100%
浏览 8643
已采纳

使用Guzzle使用JSON发送POST请求

$client = new Client();
$url = 'api-url';

$request = $client->post($url, [
    'headers' => ['Content-Type' => 'application/json'],
    'json' => ['token' => 'foo']
]);

return $request;

然后我返回了502 Bad Gateway 以及Resource解释为Document,但以MIME类型application / json传输

我需要用一些json发出POST请求。 如何在Laravel中使用Guzzle做到这一点?

  • 写回答

2条回答 默认 最新

  • duancao1951 2017-09-24 07:40
    关注

    Give it a try

    $response = $client->post('http://api.example.com', [
        'json' => [
           'key' => 'value'
         ]
    ]);
    
    dd($response->getBody()->getContents());
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?