我跟随How to post JSON to the server?创建方法帖子,但它不支持窗口电话。我在窗口电话中有另一种方法帖子:
我有字符串json
string json = "{data : {";
json += "faceID:\"" + fbID + "\"";
json += "avatar:\"" + fbAvatar + "\"";
json += "faceName:\"" + username + "\"";
json += "commentTime:\"" + cmtTime + "\"";
json += "content:\"" + cmtContent + "\"";
json += "articleID:\"" + id + "\"";
json += "}}";
string url="http://wordpriceder.com/get.php";
方法将json发布到url。
public static async Task<string> sendJsonData(string url, string json)
{
TaskCompletionSource<string> complete = new TaskCompletionSource<string>();
try
{
WebClient wc = new WebClient();
var URI = new Uri(url);
wc.Headers["Content-Type"] = "application/json;charset=utf-8";
wc.UploadStringCompleted += (s, e) =>
{
try
{
string tt = e.Result;
complete.SetResult(tt);
}
catch (Exception exc)
{
complete.SetException(exc);
}
};
wc.UploadStringAsync(URI,"POST", json);
}
catch (Exception ex)
{
string temp = ex.Message;
}
return await complete.Task;
}
但是Json没有传递到url?怎么办?还是任何解决方案?