使用" 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
}
我缺少什么想法?
答案 0 :(得分:2)
试试这个:
$client = new GuzzleHttp\Client([
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json'
],
'verify' => false
]);
$result = $client->request('GET', 'http://A001234/datadownload/test', [
"query" => [
"reference" => "abc",
"opt_responseformat" => "json",
"opt_servicemode"=> "async"
]
]);
if($result->getStatusCode() == 200) {
dd(json_decode($result->getBody())); // dumps null expecting json object
}