【发布时间】:2014-04-16 07:27:02
【问题描述】:
这个问题已经被问了一百万次,但没有一个对我有用。我最兴奋的是Http Post for Windows Phone 8,但因为它需要委托,所以它不适合我的代码...... Postdata 函数是从存储库中调用的,如果能直接从这个函数中得到响应就好了!
如何在此代码中添加帖子参数?我已经尝试让它工作了 10 个小时。
// Repository code
string url = "/bla/bla/" + blaId + "/";
Dictionary<string, string> postParams = new Dictionary<string, string>();
postParams.Add("value", message);
string response = await BlaDataContext.PostData(url, postParams);
// ...
public static async Task<string> PostData(string url, Dictionary<String, String> postParams)
{
HttpWebRequest request = WebRequest.CreateHttp(APIURL + url);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
postParams.Add("oauth_token", Contract.AccessToken); // where do I add this to the request??
try
{
HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();
Debug.WriteLine(response.ContentType);
Stream responseStream = response.GetResponseStream();
string data;
using (var reader = new StreamReader(responseStream))
{
data = reader.ReadToEnd();
}
responseStream.Close();
return data;
}
catch (Exception e)
{
// whatever
}
}
【问题讨论】:
标签: c# windows-phone-8