带有查询参数和正文的耗时发布请求

时间:2018-10-18 16:11:09

标签: php guzzle

我想使用guzzle将POST请求发送到WebService。此请求必须在查询字符串上发送2个参数,并使用form_params发送正文。

示例:http://localhost:5000/api/V1/Clients/AddClient?sitecode=PT&username=test

然后向该请求添加带有form_params的正文。

我正在尝试使用以下代码:

$Client = new \GuzzleHttp\Client([ //Instantiate the guzzle client
  'headers' => [
      'Content-Type' => 'application/json',
    ]
]);

$response = $Client->post("http://localhost:5000/api/V1/Clients/AddCustomer", [
  'headers' => [
       'Authorization' => 'Bearer '.$token
   ],
  'query' => [
      'sitecode' => "PT",
      'username' => "Test",
   ],
  'form_params' => [
      'Client' => json_encode($ClientRegister),
   ]
]);

PostMan中的所有功能均可使用

Postman Request Image

该代码返回500个内部服务器错误。预计会得到200 OK。 谁能帮我吗?

0 个答案:

没有答案