loop
loop

Reputation: 9242

Post data to server in windows store app

i want to send data to my web-service in the form of key,value pairs. i am not getting how to do this,for doing post the basic method is.

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

my Api requires pairs for getting data so plz tell me how to do it in windows 8 apps..any help is appreciated.

Upvotes: 0

Views: 1238

Answers (1)

Farhan Ghumra
Farhan Ghumra

Reputation: 15296

Try this

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();
}

Upvotes: 2

Related Questions