Reputation: 53
I have a string that I need to POST in Windows Phone 8. It looks like this:
https://www.scoreoid.com/api/getPlayers?api_key=[apiKey]&game_id=[gameID]&response=xml&username=[username]&password=[password]
This string simply returns another string (that is formatted as XML that I parse later in my code).
I have yet to find a simple solution to this like in Windows 8.
Edit: Found the solution to my problem with an assist from rciovati and the HttpClient library.
Here's my simple code:
var httpClient = new HttpClient();
return await httpClient.GetStringAsync(uri + "?" + post_data);
Upvotes: 2
Views: 12737
Reputation: 28073
Using the new Http Client Library is quite easy:
var values = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("api_key", "12345"),
new KeyValuePair<string, string>("game_id", "123456")
};
var httpClient = new HttpClient(new HttpClientHandler());
HttpResponseMessage response = await httpClient.PostAsync(url, new FormUrlEncodedContent(values));
response.EnsureSuccessStatusCode();
var responseString = await response.Content.ReadAsStringAsync();
You can find other informations about this library here.
Upvotes: 24
Reputation: 104
Here's a pretty useful blog post from Andy Wigley about how to do Http networking on Windows Phone 8. The WinPhoneExtensions wrapper library he speaks of basically simulates the async/await model of network programming you can do in Win8.
Upvotes: 0