【问题标题】:How to send Post with parameters [duplicate]如何发送带有参数的帖子[重复]
【发布时间】:2016-04-11 22:56:46
【问题描述】:

我想发送带参数的 POST,但我不知道该怎么做。

我的代码:

 Uri resourceAddress = new Uri("http://web.com/geo");
 try
 {
    HttpResponseMessage response=await httpClient.PostAsync(resourceAddress,
        new HttpStringContent("")).AsTask(cts.Token);
 }
 catch (Exception ex) { }
 finally { }

如何使用此代码发送帖子,例如:{ latitude:-1.323141, lng:24.42342 }

【问题讨论】:

    标签: c# http-post httprequest


    【解决方案1】:

    您使用要发送的键/值填充 HttpContent。

    具体来说:

    Uri resourceAddress = new Uri("http://web.com/geo");
    var values = new Dictionary<string, double>
    {
       { "latitude", -1.323141 },
       { "lng", 24.42342 }
    };
    
    var content = new FormUrlEncodedContent(values);
    
    try{
        HttpResponseMessage response=await httpClient.PostAsync(resourceAddress,
             content).AsTask(cts.Token);
     } catch (Exception ex){
     }finally{
    
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-10
      • 1970-01-01
      • 1970-01-01
      • 2013-02-28
      相关资源
      最近更新 更多