本文介绍了在Windows Phone 8的简单的HTTP POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串,我需要在Windows Phone的开机自检8.它看起来是这样的:
https://开头www.scoreoid.com/api/getPlayers?api_key=[apiKey]&game_id=[gameID]&response=xml&username=[username]&password=[password]
这串简单的返回另一个字符串(格式为XML,我在后面的代码分析)。
我还没有找到在Windows 8一个简单的解决这个像
编辑:找到了解决我的问题与来自rciovati协助和库。
下面是我简单的代码:
VAR的HttpClient =新的HttpClient();
返回等待httpClient.GetStringAsync(URI + + post_data?);
解决方案
使用新的是很容易的:
VAR值=新的List< KeyValuePair<字符串,字符串>>
{
新KeyValuePair<字符串,字符串>(API_KEY,12345),
新KeyValuePair<字符串,字符串>(game_id,123456)
};
变种的HttpClient =新的HttpClient(新HttpClientHandler());
HttpResponseMessage响应=等待httpClient.PostAsync(网址,新FormUrlEncodedContent(值));
response.EnsureSuccessStatusCode();
VAR responseString =等待response.Content.ReadAsStringAsync();
您可以找到有关这个库的。
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);
解决方案
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.
这篇关于在Windows Phone 8的简单的HTTP POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!