Windows.Web.Http.HttpClient
和System.Net.Http.HttpClient
收到不同的答复。
protected override void OnLaunched(LaunchActivatedEventArgs e) {
var client = new Windows.Web.Http.HttpClient();
var taskHttpResponse = client.GetAsync(new Uri(@"https://apis.live.net/v5.0/me?access_token=abcdefg"));
Debug.WriteLine(taskHttpResponse.AsTask().Result.Content.ReadAsStringAsync().AsTask().Result);
}
{ "error": { "code": "request_token_invalid", "message": "The access token isn't valid." } }
private static void Main() {
var client = new System.Net.Http.HttpClient();
var taskHttpResponse = client.GetAsync(new Uri(@"https://apis.live.net/v5.0/me?access_token=abcdefg"));
Console.WriteLine(taskHttpResponse.Result.Content.ReadAsStringAsync().Result);
}
} } "message": "The access token isn't valid."
你在开玩笑吗?
答案 0 :(得分:1)
您不应使用 SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
Collections.sort(templateDirs, (o1, o2) -> {
if (o1.get(3) == null || o2.get(3) == null)
return 0;
try {
boolean b = formatter.parse(o1.get(3)).before(formatter.parse(o2.get(3)));
return b ? 1:-1 ;
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
});
来使UI中的死锁见https://walterlv.github.io/post/deadlock-in-task-wait.html
我将您的代码更改为ReadAsStringAsync().Result
,可以得到结果。
我发现您使用await
的代码没有被未授权会是一个例外401。我认为该api必须在没有身份验证的情况下使用。