0

我想以键值对的形式将数据发送到我的网络服务。我不知道怎么做,做post的基本方法是。

HttpClient httpClient = new HttpClient();
HttpResponseMessage response = httpClient.PostAsync("http://50.16.234.220/helloapp/api/public/", new StringContent("asdad")).Result;

我的 Api 需要配对才能获取数据,所以请告诉我如何在 Windows 8 应用程序中进行操作。感谢任何帮助。

4

1 回答 1

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();
}
于 2013-09-16T11:23:10.610 回答