这有效:
WebClient client = new WebClient();
client.Headers[HttpRequestHeader.Authorization] = "Basic " + base64;
client.DownloadStringCompleted += getAccessToken_DownloadStringCompleted;
client.DownloadStringAsync(new Uri(URL));
但是,我需要将它移动到HttpClient(因为我已经开始使用可移植类库),所以我得到了这个:
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64);
string response = await client.GetStringAsync(URL);
但是这里的HttpClient在周围的try / catch中失败了
Response status code does not indicate success: 400 (Bad Request).
我真的没有看到任何差异......?可能是什么问题?