请求html中的数组参数不起作用

时间:2016-11-05 13:19:45

标签: c# html json

在Chrome开发者工具,XHR选项中,我有以下信息:

请求网址:https://pmv.geocontrol.com.br/pontovitoria/svc/json/db/listarPontosDeParada

请求有效负载: {listaIds:[216,147,607,601,79]}

我正在尝试用独特的html转换它,比如

https://pmv.geocontrol.com.br/pontovitoria/svc/json/db/listarPontosDeParada?listaIds[0]=216&listaIds[1]=147&listaIds[2]=607&listaIds[3]=601&listaIds[4]=79

但我收到此错误

errorClass:“javax.servlet.ServletException”, 消息:“org.postgresql.util.PSQLException:错误:语法错误在或附近”)“位置:273”

我正在使用C#开发一个应用程序,我尝试了这个帖子请求:

public async void GetList()
{
        int[] list = new int[] { 216, 147, 607, 601, 79 };

        var client = new HttpClient();
        client.DefaultRequestHeaders.Add("User-Agent", "Other");
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        client.DefaultRequestHeaders.IfModifiedSince = DateTime.Now;

        Dictionary<string, string> bodyProperties = new Dictionary<string, string>();

        int i = 0;
        foreach (var pto in list)
        {
            bodyProperties.Add("listaIds[" + i.ToString() + "]", pto.ToString());
            i++;
        }

        var content = new FormUrlEncodedContent(bodyProperties);
        var response = await client.PostAsync("https://pmv.geocontrol.com.br/pontovitoria/svc/json/db/listarPontosDeParada", content);
        var responseString = await response.Content.ReadAsStringAsync();
}

这不行。我该如何解决?

1 个答案:

答案 0 :(得分:0)

感谢您的评论。我找到了解决方案。

正确的网址是:

https://pmv.geocontrol.com.br/pontovitoria/svc/json/db/listarPontosDeParada?listaIds[]=216,147,607,601,79