Question

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.

Maybe I have missed something, so if anyone knows a class that supports downloading and uploading with authentication and headers, please share your code.

Était-ce utile?

La solution 2

solved it, the whole problem was the request method, it needed a post not a get, i figured it out by using wireshark software.

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
        };

Autres conseils

The BackgroundTransfer API is supposed to handle headers and auth. Headers are set in the SetRequestHeader method of BackgroundDownloader and BackgroundUploader. This method is designed to call multiple times, once for each header needed.

Both then have ServerCredential and ProxyCredential properties. These are both instance of a Windows.Security.Credentials.PasswordCredential objects (http://msdn.microsoft.com/library/windows/apps/windows.security.credentials.passwordcredential.aspx). You’d typically create a PasswordCredential as follows:

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

Are you saying that both headers and creds work separately but not together? How have you testing them?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top