我读了这个答案,但我相信有更好的方法在Guzzle中创建一个http url查询,我正在寻找这样的东西,但是无法让它正常工作,我也不知道是否有办法转储网址字符串,以查看它是否正确处理.有人能告诉我这样做的正确方法吗?
// works correctly
$client = New GuzzleHttp\Client();
$request = $client->get('http://192.168.50.8/foo?-db=database&-lay=layout&-find');
print_r($request->getBody());
Run Code Online (Sandbox Code Playgroud)
不行
$request = $client->get($config->Layout['server'], [], [
'query' => [
$config->Layout['switches'], // ([ '-db' => 'database', '-lay' => 'layout', '-find' => true)
$config->Layout['options'], // other params
]
]);
Run Code Online (Sandbox Code Playgroud)
use*_*315 26
我也有同样的问题.我找到了解决方案
public static function getGroupList($current=false) {
$response = self::getRestClient()->get(
[
'domains/{domainId}/pricelists',
['domainId' => self::getDomainId()]
],
[
'query' => [
current => $current
]
]
);
return new RestResponse($response);
Run Code Online (Sandbox Code Playgroud)
尝试
$response = $client->get(
[
$config->Layout['server'],
[]
],
[
'query' => [
$config->Layout['switches'], // ([ '-db' => 'database', '-lay' => 'layout', '-find' => true)
$config->Layout['options'], // other params
]
]
);
Run Code Online (Sandbox Code Playgroud)
kal*_*azy 10
正确答案的另一种形式:
$params = [
'query' => [
'option_1' => string,
'option_2' => string
]
];
Run Code Online (Sandbox Code Playgroud)
然后调用您的请求:
$response = $guzzle_client->request('GET','/api.com',$params);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34787 次 |
| 最近记录: |