代码之家  ›  专栏  ›  技术社区  ›  Cristian Gonzalez

PHP GuzzleHttp。如何发送json帖子?

  •  0
  • Cristian Gonzalez  · 技术社区  · 6 年前

    我有这个帖子:

    {"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}']
    

    但它不起作用,有没有办法发送所有内容而不按我发布的格式进行格式化?谢谢

    1 回复  |  直到 6 年前
        1
  •  1
  •   Volkan Yılmaz    6 年前

    创建客户端对象的第一步

    $client = new Client([
         'http_errors' => false,
         'verify'      => false,
    ]);
    

    然后你和params的请求

    $response = $client->request($requestMethod, $url, array_merge(
        ['json' => $body],
        ['headers' => $headers]
    ));