locked
How to set cookie in BackgroundUploader

    Question

  • Hello,

    How to set cookie in backgrounduploader. I tried below code but it's not working

    backgroundUploader.SetRequestHeader("Cookie", "ID=SomeValue");
    backgroundUploader.SetRequestHeader("Cookie", "UNAME=SomeValue");
    
    Thanks in advance.
    Tuesday, July 15, 2014 10:02 AM

Answers

  • try something like this:

    System.Net.CookieContainer container = new CookieContainer();
                    container.Add(new Uri("http://urlofserver"), collection);
    
                    string cookieheader = container.GetCookieHeader(new Uri("http://urlofserver"))
    
                    BackgroundDownloader downloader = new BackgroundDownloader();
                    downloader.SetRequestHeader("Cookie", cookieheader);
                    var download = downloader.CreateDownload("http://urlofserver/file.bin", file);
    

    and with the
    GetResponseInformation
     method you can see the server response. You will need to debug that to see where it's going wrong.


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Wednesday, July 16, 2014 1:14 PM
  • Hi Dave,

    Thanks for your reply.

    I will try that. Currently as a temporary solution I am using HttpClient to achieve that and it is working fine.

    Monday, July 21, 2014 1:34 PM

All replies

  • try to combine them

    backgroundUploader.SetRequestHeader("Cookie", "UNAME=SomeValue;ID=SomeValue;");

    if use a CookieCOllection you get get the string by using the method GetCookieHeader()


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Tuesday, July 15, 2014 11:36 AM
  • Hi Dave,

    Thanks for your reply,

    I also tried that but still not working. May be something wrong with server. don't know exactly what is going wrong.

    Wednesday, July 16, 2014 12:58 PM
  • try something like this:

    System.Net.CookieContainer container = new CookieContainer();
                    container.Add(new Uri("http://urlofserver"), collection);
    
                    string cookieheader = container.GetCookieHeader(new Uri("http://urlofserver"))
    
                    BackgroundDownloader downloader = new BackgroundDownloader();
                    downloader.SetRequestHeader("Cookie", cookieheader);
                    var download = downloader.CreateDownload("http://urlofserver/file.bin", file);
    

    and with the
    GetResponseInformation
     method you can see the server response. You will need to debug that to see where it's going wrong.


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Wednesday, July 16, 2014 1:14 PM
  • Hi Dave,

    Thanks for your reply.

    I will try that. Currently as a temporary solution I am using HttpClient to achieve that and it is working fine.

    Monday, July 21, 2014 1:34 PM