php - Symfony HttpClient GET 请求具有多个具有相同名称的查询字符串参数
问题描述
我正在尝试以以下格式发出 API 请求:
/api/v1/courses?enrollment_state=active&include[]=total_students&include[]=term
如何使用HttpClient
组件查询字符串参数执行此操作?
$response = $client->request('GET', '/api/v1/courses', [
'query' => [
'enrollment_state' => 'active',
'include[]' => 'term',
'include[]' => 'total_students',
],
]);
由于重复的数组键,上述方法不起作用?
我也试过:
'include[]' => ['term', 'total_students']
解决方案
创建等效于:
https://www.example.com/?token=foo&abc[]=one&abc[]=two
做就是了:
$client->request(
'GET',
'https://www.example.com/',
[
'query' => [
'token' => 'foo',
'abc' => ['one', 'two']
]
]
);
推荐阅读
- java - 如何从当前活动检查/访问不同活动的生命周期?
- javascript - JavaScript ES6 返回 undefined 虽然已设置
- ruby-on-rails - 无法为 firebase 自定义声明添加适当的规则
- api - Facebook graph api 获取用户信息
- c# - MVC OutputCaching - 为什么不应该使用页面指令?
- r - Rpresentation 中的表格样式
- sql - 如何使用 SQL Server 在静态/动态数据透视查询中将两列组合成单列
- logging - jBoss eap 5.1 run.log 太大
- swift - Swift - 将代表连接到自定义 Xib 单元
- javascript - CryptoJS:key.clamp 不是一个函数