I have some very large files I need to download in my Android App. (Resource bundles and videos, some upwards of 70MB).
The problem I have when using the WWW class is that the whole file is downloaded and kept in memory before you get access to it, and this is crashing my App.
The solution I came up with was to use the System.Net.WebClient class to download and save directly to the disk.
This works great, but the only problem I have is whenever the phone is using a Proxy, the WebClient can’t connect to the server (even when other web requests in my app succeed - the GoogleIAP and Flurry plugins from Prime31 work a treat)
So obviously I’m missing something in my code relating to the way I set up my WebClient, but I’m at a loss.
Here is the code I’m using:
WebClient webClient = new WebClient(); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler (OnDownloadComplete); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(OnUpdateDownloadProgress); Uri uri = new Uri(AbsoluteURI); webClient.DownloadFileAsync(uri, FilePath );
AbsoluteURI and FilePath are strings, there are no problems with these values, they contain the information they should and go to the right places.
The error I get back from the WebClient is:
I/Unity (14191): System.Net.WebException: Error: ConnectFailure (Connection refused) ---> System.Net.Sockets.SocketException: Connection refused I/Unity (14191): at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0 I/Unity (14191): at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x00000] in <filename unknown>:0 I/Unity (14191): --- End of inner exception stack trace --- I/Unity (14191): at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 I/Unity (14191): at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
Any help is appreciated. To be honest, I’m not even 100% sure that the WebClient is the correct way to do what I want.