我想以密钥,值对的形式向我的网络服务发送数据。我没有得到如何做到这一点,因为做基本方法的帖子是。
HttpClient httpClient = new HttpClient();
HttpResponseMessage response = httpClient.PostAsync("http://50.16.234.220/helloapp/api/public/", new StringContent("asdad")).Result;
我的Api需要成对才能获取数据,所以请告诉我如何在Windows 8应用程序中执行此操作..非常感谢。
答案 0 :(得分:2)
试试这个
using System.Net.Http;
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
var data = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("key_1", "value_1"),
new KeyValuePair<string, string>("key_2", "value_1")
};
await PostKeyValueData(data);
}
private async Task PostKeyValueData(List<KeyValuePair<string, string>> values)
{
var httpClient = new HttpClient();
var response = await httpClient.PostAsync("http://50.16.234.220/helloapp/api/public/", new FormUrlEncodedContent(values));
var responseString = await response.Content.ReadAsStringAsync();
}