This project has moved. For the latest updates, please go here.
1

Closed

Dont work through proxy

description

correct TileImageLoader.WPF:
private static ImageSource DownloadImage(Uri uri, string cacheKey)
    {
        BitmapSource image = null;

        try
        {
            var request = HttpWebRequest.CreateHttp(uri);
            request.UserAgent = HttpUserAgent;
            request.Proxy = WebRequest.DefaultWebProxy;
            request.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
            using (var response = (HttpWebResponse)request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                using (var memoryStream = new MemoryStream())
                {
                    responseStream.CopyTo(memoryStream);
                    memoryStream.Position = 0;
                    image = BitmapFrame.Create(memoryStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                }

                if (cacheKey != null)
                {
                    SetCachedImage(cacheKey, image, GetExpiration(response.Headers));
                }
            }
        }
        catch (WebException ex)
        {
            Debug.WriteLine("Downloading {0} failed: {1}: {2}", uri, ex.Status, ex.Message);
        }
        catch (Exception ex)
        {
            Debug.WriteLine("Downloading {0} failed: {1}", uri, ex.Message);
        }

        return image;
    }
Closed Dec 10, 2015 at 8:01 PM by ClemensF
WebRequest.DefaultWebProxy is already the default value of the HttpWebRequest.Proxy property. Same for credentials. This is nonsense.

comments