简体   繁体   English

Windows应用商店中下载和上传文件的最佳用途是什么?

[英]What is the best use of download and upload files in a windows store app?

I have tried using a lot of classes to download and upload files plus adding headers and authentication but none of these classes supported both! 我尝试使用许多类来下载和上传文件,以及添加标头和身份验证,但是这些类都不支持两者!

I have tried backgrounddownloader, backgrounduploader, httpclient, httpwebclient, httprequestmessage classes but all of them failed me. 我尝试了backgrounddownloader,backgrounduploader,httpclient,httpwebclient,httprequestmessage类,但是它们都使我失败了。

Maybe I have missed something, so if anyone knows a class that supports downloading and uploading with authentication and headers, please share your code. 也许我错过了一些东西,所以如果有人知道支持通过身份验证和标头下载和上传的类,请共享您的代码。

The BackgroundTransfer API is supposed to handle headers and auth. 应该使用BackgroundTransfer API处理标头和身份验证。 Headers are set in the SetRequestHeader method of BackgroundDownloader and BackgroundUploader. 标头是在BackgroundDownloader和BackgroundUploader的SetRequestHeader方法中设置的。 This method is designed to call multiple times, once for each header needed. 此方法旨在多次调用,每个所需的标头一次。

Both then have ServerCredential and ProxyCredential properties. 然后两者都具有ServerCredential和ProxyCredential属性。 These are both instance of a Windows.Security.Credentials.PasswordCredential objects ( http://msdn.microsoft.com/library/windows/apps/windows.security.credentials.passwordcredential.aspx ). 这些都是Windows.Security.Credentials.PasswordCredential对象( http://msdn.microsoft.com/library/windows/apps/windows.security.credentials.passwordcredential.aspx )的实例。 You'd typically create a PasswordCredential as follows: 通常,您将创建一个PasswordCredential,如下所示:

var cred = new Windows.Security.Credentials.PasswordCredential(resource, userName, password);

where the resource in this case is just a string that identifies the resource to which the credentials applies (typically used with the Credential Locker API, not that important here). 其中,在这种情况下,资源只是一个字符串,用于标识凭据所应用的资源(通常与凭据锁定器API一起使用,此处并不重要)。

Are you saying that both headers and creds work separately but not together? 您是说标头和信用分别工作,但不能一起工作吗? How have you testing them? 您如何测试它们?

solved it, the whole problem was the request method, it needed a post not a get, i figured it out by using wireshark software. 解决了它,整个问题是请求方法,它需要一个帖子而不是获取,我通过使用wireshark软件就知道了。

var uri = new Uri("");
        var downloader = new BackgroundDownloader();

        downloader.SetRequestHeader("Range", "bytes=0-");
        downloader.Method = "POST";

        downloader.SetRequestHeader("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundaryx5pLn3bHAS5Q8Ns5");

        downloader.ServerCredential = new Windows.Security.Credentials.PasswordCredential()
        {
            UserName = signin.theusername,
            Password = signin.thepassword
        };

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

相关问题 在Windows Store App中将文件上传到Google云端硬盘 - Upload files to Google Drive in Windows Store App 将文件从iOS应用程序上传到Windows Server的最佳方法? - Best way to upload files from iOS app to Windows Server? 在Windows Store App中将文件上传/下载到Google云端硬盘 - Upload/Downloading files to Google Drive in Windows Store App Windows Store应用程序-在下载类中使用进度栏 - Windows Store App - Use Progress Bar in a Download Class Windows Store App的登录屏幕-最好的方法是什么? - Login Screen for Windows Store App - What would be the best approach? 在Windows 8.1应用程序中存储保存的用户帐户的最佳方法是什么 - What is the best method to store saved user accounts in a windows 8.1 app 在Windows应用商店应用中使用Azure表存储的最佳做法是什么? - What is the best practice to consume Azure table storage in a windows store app? 存储动态上传文件的最佳做法是什么(上传服务器文件夹或子文件夹的位置)? - What is best practices to store dynamically uploaded files(Where to upload server folder or sub folder)? Windows应用商店应用,使用线程下载多个文件 - Windows Store Apps, download multiple files with threads 下载Windows Store应用程式8.1的地图 - Download Maps for Windows Store app 8.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM