locked
Windows 8.1 store app Download file using authentication and header

    Question

  • I'm trying to download a file from a server and adding authentication and range header in my app, so is this syntax correct?

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
                            request.Headers["Range"] = "bytes=0-";
                            request.Credentials = new NetworkCredential("username","password");

    Of course the code has other parts for reading the file as a stream and storing it but i'm concerned with the range header and authentication part because it's not working.

    I get an exception:

    {"The 'Range' header must be modified using the appropriate property or method.\r\nParameter name: name"}
    Thursday, May 8, 2014 2:01 PM

Answers

  • I think you'll be better off using HttpClient:

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn440594.aspx


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, May 8, 2014 7:16 PM
    Moderator