如何发送带参数的Post

How to send Post with parameters

我想发送带参数的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 { }

如何发送 post 代码,例如:{ latitude:-1.323141, lng:24.42342 }

您使用要发送的 key/values 填充 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{

 }