gpt4 book ai didi

php - 如何使用 Guzzle 以 JSON 格式发送 POST 请求?

转载 作者:IT老高 更新时间:2023-10-28 11:43:15 28 4
gpt4 key购买 nike

有人知道使用 Guzzle post JSON 的正确方法吗?

$request = $this->client->post(self::URL_REGISTER,array(
'content-type' => 'application/json'
),array(json_encode($_POST)));

我从服务器收到 internal server error 响应。它使用 Chrome Postman 工作。

最佳答案

对于 Guzzle 5、6 和 7,您可以这样做:

use GuzzleHttp\Client;

$client = new Client();

$response = $client->post('url', [
GuzzleHttp\RequestOptions::JSON => ['foo' => 'bar'] // or 'json' => [...]
]);

Docs

关于php - 如何使用 Guzzle 以 JSON 格式发送 POST 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22244738/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com