从WebClient转换为HttpClient,发送身份验证的问题

时间:2013-11-27 20:22:44

标签: c# windows-phone-8 portable-class-library dotnet-httpclient

这有效:

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).

我真的没有看到任何差异......?可能是什么问题?

0 个答案:

没有答案