将查询字符串参数添加到Guzzle GET请求中? [英] Adding Query string params to a Guzzle GET request?
本文介绍了将查询字符串参数添加到Guzzle GET请求中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我阅读了此答案,但我相信有更好的方法在Guzzle中创建一个http url查询,我正在寻找类似的东西,但是无法使其正常工作,也不知道是否有一种方法可以转储url字符串以查看其是否正确处理.有人可以告诉我正确的方法吗?
I read this answer but I believe there is a better way to create a http url query in Guzzle, I am looking for something like this, but cannot get it to work correctly, nor do I know if there is a way to dump the url string to see if it is processing correctly. Could someone show me the correct way to do this?
// works correctly
$client = New GuzzleHttp\Client();
$request = $client->get('http://192.168.50.8/foo?-db=database&-lay=layout&-find');
print_r($request->getBody());
不起作用
$request = $client->get($config->Layout['server'], [], [
'query' => [
$config->Layout['switches'], // ([ '-db' => 'database', '-lay' => 'layout', '-find' => true)
$config->Layout['options'], // other params
]
]);
推荐答案
我有同样的问题.我找到了解决办法
I have the same problem. I found solution
public static function getGroupList($current=false) {
$response = self::getRestClient()->get(
[
'domains/{domainId}/pricelists',
['domainId' => self::getDomainId()]
],
[
'query' => [
current => $current
]
]
);
return new RestResponse($response);
尝试
$response = $client->get(
[
$config->Layout['server'],
[]
],
[
'query' => [
$config->Layout['switches'], // ([ '-db' => 'database', '-lay' => 'layout', '-find' => true)
$config->Layout['options'], // other params
]
]
);
这篇关于将查询字符串参数添加到Guzzle GET请求中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文