【发布时间】:2014-10-12 13:07:18
【问题描述】:
我想发送带有多个同名参数的 POST 请求:
FormUrlEncodedContent content = new FormUrlEncodedContent(new [] {
new KeyValuePair < string, string > ("group_id", "344"),
new KeyValuePair < string, string > ("group_id", "20"),
new KeyValuePair < string, string > ("group_id", "456")
});
HttpResponseMessage response = await _httpClient.PostAsync("http://localhost/api", content);
但如果我使用上述请求,我只会收到第一个 group_id(ID 为 344)的响应。您知道如何使用 FormUrlEncodedContent 获取 "group_id[]=344&group_id[]=20&group_id[]=456" 吗?
【问题讨论】:
-
您是否尝试过像这样 [344, 20, 456] 将 group_id 作为键和值作为数组传递?
-
我试过类似:
FormUrlEncodedContent content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string[]>("group_id", new string[] {"344", "20"} ) });但是,我得到错误:1. 'System.Net.Http.FormUrlEncodedContent.FormUrlEncodedContent(System.Collections.Generic. IEnumerable>)' 有一些无效参数