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.