1

In my windows phone application, i want to download zip file from the server. I used Background Transfer Service for downloading file. And it works for me for some service urls.

But now i tried with downloading file from a url, [Actually on hitting it is redirected to another url] for downloading the actual data.

By using Http Web Request method, i am able to download the data, but on using background transfer service it's status is always on a waiting stage .

    public AddBackgroundTransfer()
    {
        InitializeComponent();
        var url= "www.firsturl.com";

        using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (!isoStore.DirectoryExists("/shared/transfers"))
            {
                isoStore.CreateDirectory("/shared/transfers");
            }
        }

    BackgroundTransferRequest transferRequest = new BackgroundTransferRequest(transferUri);
    transferRequest.Method = "GET";

    //adding headers
    Dictionary<string, string> headers = new Dictionary<string, string>();
        headers.Add("APPKEY", "somekey");            

        if (headers != null)
        {
            foreach (var key in headers.Keys)
            {
                transferRequest.Headers.Add(key, headers[key]);
            }
        }

        Uri downloadUri = new Uri("shared/transfers/" + "myfile, UriKind.RelativeOrAbsolute);
        transferRequest.DownloadLocation = downloadUri;

        try
        {
            BackgroundTransferService.Add(transferRequest);
        }
        catch (InvalidOperationException ex)
        {
            MessageBox.Show("Unable to add background transfer request. " + ex.Message);
        }
        catch (Exception)
        {
            MessageBox.Show("Unable to add background transfer request.");
        }

    }

    private void ProcessTransfer(BackgroundTransferRequest transfer)
    {
        switch (transfer.TransferStatus)
        {
          //case

        }
    }

Here am getting Status as Waiting and BytesToRecieve Value is always -1. And the redirection status seems 302.

And i tried this with Fiddler, there it is redirected in to another url and downloading starts.

Do i need to set any value value to correct it? Please provide me any suggestion.

asitis
  • 3,023
  • 1
  • 31
  • 55
  • Suggestion: post some code. :-) Also, are you testing this in the emulator, or do you only see this behaviour on a device? Also: what kind of redirect is happening on the target Url? – Dan Puzey Aug 04 '14 at 14:15
  • @DanPuzey Hi i updated answer. But sorry for not revealing the exact download url since it is confidential. The urls which is not redirecting is working fine with the background transfer . – asitis Aug 04 '14 at 14:31
  • Can you answer the second question? How is the redirect being handled? (Is it a 301 or 302 status, or other?) – Dan Puzey Aug 04 '14 at 14:42
  • @DanPuzey I s there any problem in that case? – asitis Aug 04 '14 at 15:15

1 Answers1

2

The background downloader wont download the redirect urls. you need to check with the server whether the download url is available one or not

Jashif
  • 109
  • 5
  • is there anyway to get the redirect url from the original url ? so i can pass it to the background download . – asitis Aug 05 '14 at 12:15