Quantcast
Channel: Latest Questions by hkessock
Viewing all articles
Browse latest Browse all 51

HttpWebRequest and HTTPS on iOS

$
0
0
I have some dynamic file downloading code that works great on all platforms except when using an HTTPS URL on iOS. I am using HttpWebRequest because these resources are being loaded in a background thread (and you can't use WWW from another thread.) On all the other platforms I have tried, Windows/OSX/Android, using an HTTPS URL works fine. On iOS, I get an exception with "ConnectFailure" as the message... The code used is below: private void LoadRemoteImages( List in_aImageURLs ) { try { //We only support JPG or PNG foreach( string l_strTextureURL in in_aImageURLs ) { try { //We only support JPG or PNG string l_strExtension = Path.GetExtension( l_strTextureURL ).ToLower(); if( ( l_strExtension != ".jpg" ) && ( l_strExtension != ".png" ) ) { Debug.LogError( "Unsupported or missing extension found in LoadRemoteImages, the extension was: " + l_strExtension ); continue; } Debug.Log( "Attempting to download: " + l_strTextureURL ); HttpWebRequest request = (HttpWebRequest)WebRequest.Create( l_strTextureURL ); request.Method = WebRequestMethods.Http.Get; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); /* Check that the remote file was found. The ContentType check is performed since a request for a non-existent image file might be redirected to a 404-page, which would yield the StatusCode "OK", even though the image was not found. */ if( ( response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Moved || response.StatusCode == HttpStatusCode.Redirect ) && response.ContentType.StartsWith( "image", StringComparison.OrdinalIgnoreCase ) ) { string l_strLocalFilename = m_strApplicationDataPath + "/" + _Utility.HashStringToFilename( l_strTextureURL ); //Download it using( Stream inputStream = response.GetResponseStream() ) using( Stream outputStream = File.OpenWrite( l_strLocalFilename ) ) { byte[] buffer = new byte[ 16384 ]; int bytesRead; do { bytesRead = inputStream.Read( buffer, 0, buffer.Length ); outputStream.Write( buffer, 0, bytesRead ); } while( bytesRead != 0 ); } } else { Debug.Log( "Bad response from web server, file was not downloaded..." ); } } catch( WebException l_oException ) { Debug.LogError( "WebException status -> " + l_oException.Status.ToString() ); if( l_oException.Response != null ) { Debug.LogError( "WebException Response -> " + l_oException.Response.ToString() ); } else { Debug.LogError( "WebException Response is NULL" ); } Debug.LogError( "WebException -> " + l_oException.ToString() ); } catch( Exception l_oException ) { Debug.LogError( "Exception caught try to download remote image: " + l_strTextureURL + " the exception was -> " + l_oException.Message); } } } finally { m_bLoaderThreadStillWorking = false; } } Has anyone successfully used HttpWebRequest over HTTPS on iOS? Cheers :)

Viewing all articles
Browse latest Browse all 51

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>