有人知道post使用JSON 的正確方法Guzzle嗎?$request = $this->client->post(self::URL_REGISTER,array( 'content-type' => 'application/json' ),array(json_encode($_POST)));我internal server error從服務器收到響應。它可以使用Chrome瀏覽器Postman。
3 回答

滄海一幻覺
TA貢獻1824條經驗 獲得超5個贊
對于Guzzle 5和6,您可以這樣做:
use GuzzleHttp\Client;
$client = new Client();
$response = $client->post('url', [
GuzzleHttp\RequestOptions::JSON => ['foo' => 'bar']
]);

開心每一天1111
TA貢獻1836條經驗 獲得超13個贊
對于Guzzle <= 4:
這是原始的發(fā)布請求,因此將JSON放入正文即可解決問題
$request = $this->client->post($url,array(
'content-type' => 'application/json'
),array());
$request->setBody($data); #set body!
$response = $request->send();
return $response;
- 3 回答
- 0 關注
- 5532 瀏覽
添加回答
舉報
0/150
提交
取消