【发布时间】:2018-04-01 16:24:12
【问题描述】:
使用“guzzlehttp/guzzle”:“^6.3”,如何将包含查询参数的 URL 转换为使用选项数组的语法?
$exampleUrl = http://A001234/datadownload/test?reference=abc&opt_responseformat=json&opt_servicemode=async
将其粘贴到浏览器或 POSTMAN 中会给我一个不错的 JSON 小桩。但是我无法将它与选项数组一起使用。这是我尝试过的一些代码:
$client = new GuzzleHttp\Client([
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json'
],
'verify' => false
]);
$result = $client->request('GET', 'http://A001234/datadownload/test', [
"form_params" => [
"opt_responseformat" => "json",
"opt_servicemode"=> "async"
]
]);
if($result->getStatusCode() == 200) {
dd(json_decode($result->getBody())); // dumps null expecting json object
}
任何想法我错过了什么?
【问题讨论】: