我想发送带参数的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 }
答案 0 :(得分: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{
}