PHP GuzzleHttp。如何发送jsonpost?
PHP GuzzleHttp . How to send a json post?
我有这个post:
{"latitude":"","longitude":"","countryCode":"ES","filterPostalCode":"","filterCity":"","filterCountryCode":"ES","searchText":"","nextPageToken":0,"storeType":"normal","checkStoreAvailability":false}
我正尝试在 Guzzle 6.0+ 上像这样发送它
'headers' => [
'Content-Type' => 'application/json',
'Referer' => 'https://www.rituals.com/es-es/stores'],
'body' => '{"latitude":"","longitude":"","countryCode":"ES","filterPostalCode":"","filterCity":"","filterCountryCode":"ES","searchText":"","nextPageToken":0,"storeType":"normal","checkStoreAvailability":false}']
但它不起作用,有什么方法可以发送所有内容而不像我 posted 那样格式化?谢谢!
首先创建客户端对象
$client = new Client([
'http_errors' => false,
'verify' => false,
]);
然后你的请求和参数
$response = $client->request($requestMethod, $url, array_merge(
['json' => $body],
['headers' => $headers]
));
我有这个post:
{"latitude":"","longitude":"","countryCode":"ES","filterPostalCode":"","filterCity":"","filterCountryCode":"ES","searchText":"","nextPageToken":0,"storeType":"normal","checkStoreAvailability":false}
我正尝试在 Guzzle 6.0+ 上像这样发送它
'headers' => [
'Content-Type' => 'application/json',
'Referer' => 'https://www.rituals.com/es-es/stores'],
'body' => '{"latitude":"","longitude":"","countryCode":"ES","filterPostalCode":"","filterCity":"","filterCountryCode":"ES","searchText":"","nextPageToken":0,"storeType":"normal","checkStoreAvailability":false}']
但它不起作用,有什么方法可以发送所有内容而不像我 posted 那样格式化?谢谢!
首先创建客户端对象
$client = new Client([
'http_errors' => false,
'verify' => false,
]);
然后你的请求和参数
$response = $client->request($requestMethod, $url, array_merge(
['json' => $body],
['headers' => $headers]
));