Windows phone 7 WebClient未向Windows Phone中的Web服务发送授权标头
以下是Windows Phone上WebClient的情况。Windows phone 7 WebClient未向Windows Phone中的Web服务发送授权标头,windows-phone-7,asp.net-web-api,webclient,restful-authentication,Windows Phone 7,Asp.net Web Api,Webclient,Restful Authentication,以下是Windows Phone上WebClient的情况。 我能够将数据拉入并推送到由asp.net web Api托管的web服务。 现在,我在Web服务和Windows Phone上启用了基本身份验证。代码将标题添加到WebClient。 我注意到授权标头没有到达web服务,因此web服务抛出错误的请求。 已搜索stackoverflow和博客,但无法获取web服务的授权标头。 在上述问题上的一些方向将大有裨益 由于某些原因,webclient没有发送授权标头 我已经从我的网络中询问了一位
我能够将数据拉入并推送到由asp.net web Api托管的web服务。
现在,我在Web服务和Windows Phone上启用了基本身份验证。代码将标题添加到WebClient。
我注意到授权标头没有到达web服务,因此web服务抛出错误的请求。
已搜索stackoverflow和博客,但无法获取web服务的授权标头。
在上述问题上的一些方向将大有裨益 由于某些原因,webclient没有发送授权标头 我已经从我的网络中询问了一位windows phone champ。他建议安装nuget包HttpClient。并使用HttpClient而不是WebClient。此HttpClient在wp7上支持异步和等待。可以很容易地让它工作 示例代码:
string api = "/api/example/?id=abc";
var client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:0000/");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue
("Basic", Convert.ToBase64String
(
new Helpers().StringToAscii(Username, Password)
)
);
var resultString = await client.GetStringAsync(api);
希望这有帮助。看看这个问题:-我认为你也有同样的问题,尽管你必须给我们提供更多信息。