简体   繁体   English

提供BackgroundTransferRequest(WP8)的凭据

[英]Provide Credentials for BackgroundTransferRequest (WP8)

When I am using HttpWebRequest I use the following code to set the Credentials 当我使用HttpWebRequest时,我使用以下代码来设置凭据

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlToCall);
request.Method = "GET";
request.Credentials = new NetworkCredential(username, pass);

How do I do the same when I am using BackgroundTransferService in Windows Phone 8. 在Windows Phone 8中使用BackgroundTransferService时,我该怎么做?

For reference I am using the following. 供参考,我使用以下内容。
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202955%28v=vs.105%29.aspx http://msdn.microsoft.com/zh-CN/library/windowsphone/develop/hh202955%28v=vs.105%29.aspx
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202959%28v=vs.105%29.aspx http://msdn.microsoft.com/zh-CN/library/windowsphone/develop/hh202959%28v=vs.105%29.aspx

*Edit: The authentication method is Digest This is what I get in the Authorization Header when I use my browser to download the file. *编辑:身份验证方法为摘要这是我使用浏览器下载文件时在授权标题中获得的内容。

Digest username="adf", realm="bcd", nonce="XXXXXXXXX", uri="/ans/1268e52399.txt", algorithm=MD5, response="XXXXXXXXXXXXXXX", qop=auth, nc=00000001, cnonce="XXXXXXXXXXXX" 摘要用户名=“ adf”,领域=“ bcd”,nonce =“ XXXXXXXXX”,uri =“ / ans / 1268e52399.txt”,算法= MD5,响应=“ XXXXXXXXXXXXXXX”,qop = auth,nc = 00000001,cnonce = “ XXXXXXXXXXXX”

Unfortunately this isn't supported on the BackgroundTranserService. 不幸的是,BackgroundTranserService不支持此功能。 One possible solution might be to manually create a header for your request like below: 一种可能的解决方案可能是为您的请求手动创建标头,如下所示:

var credentials = new UTF8Encoding().GetBytes(username + ":" +password);

var transferRequest = new BackgroundTransferRequest(transferUri);

transferRequest.Headers["Authorization"] ="Basic " + convert.ToBase64String(credentials);

Unfortunately I'm unable to test this at the minute, give it a try and let me know how you get on. 不幸的是,我暂时无法对此进行测试,请尝试一下,让我知道您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM