Uzing狂饮发送POST请求qith JSON
问题描述:
$client = new Client();
$url = 'api-url';
$request = $client->post($url, [
'headers' => [ 'Content-Type' => 'application/json' ],
'json' => ['token' => 'foo']
]);
return $request;
我也得到502 Bad Gateway
和资源解释为文档,但与MIME类型application/JSONUzing狂饮发送POST请求qith JSON
我需要做一些JSON POST请求转移。如何在Guzzle和Laravel中做到这一点?
答
试试看
$request = $client->post('http://api.example.com', [
'json' => [
'key' => 'value'
]
);
dd($result->getBody()->getContents());
答
看看..
$client = new Client();
$url = 'api-url';
$headers = array('Content-Type: application/json');
$data = array('json' => array('token' => 'foo'));
$request = new Request("POST", $url, $headers, json_encode($data));
$response = $client->send($request, ['timeout' => 10]);
$data = $response->getBody()->getContents();
+0
我设法做到了。谢谢 – Kira
@KiraArik其中狂饮的版本,您使用的? –
这工作!非常感谢!!! – Kira