This class should be used when ever you are using a link that is actually redirecting to the destination link that you want to use as the data source. A good example of that is a link that forwards like the current nuget link that is configured as a default location for nuget packages.
상속: HttpClient
예제 #1
0
        private Uri ResolveBaseUrl()
        {
            Uri uri;

            try
            {
                var client = new RedirectedHttpClient(new Uri(Source));
                uri = client.Uri;
            }
            catch (WebException ex)
            {
                var response = (HttpWebResponse)ex.Response;
                if (response == null)
                {
                    throw;
                }

                uri = response.ResponseUri;
            }

            return(EnsureTrailingSlash(uri));
        }
예제 #2
0
 private string GetSafeRedirectedUri(string url)
 {
     try {
         Uri uri = new Uri(url);
         IWebProxy proxy = _cachedProxy;
         RedirectedHttpClient client = new RedirectedHttpClient(uri, proxy);
         return client.Uri.ToString();
     }
     catch (WebException e) {
         if (WebExceptionStatus.Timeout == e.Status) {
             // rethrow the error because if ran into a timeout issue then
             // we don't want the code to continue as there is not going to be any good
             // result if we can't return a valid url to the caller.
             throw;
         }
         // we are assuming here that we just got a 403 - Forbidden: Access is denied error
         // because we are navigating to the publish url of the Gallery Server so we simply
         // catch the error and return the response url of the response that can be used for publishing
         // the reason why we get this error is because this is a POST action and IIS gives us this error
         // because it things that we are trying to navigate to a page.
         return e.Response.ResponseUri.ToString();
     }
 }
예제 #3
0
 private string GetSafeRedirectedUri(string url)
 {
     try {
         Uri                  uri    = new Uri(url);
         IWebProxy            proxy  = _cachedProxy;
         RedirectedHttpClient client = new RedirectedHttpClient(uri, proxy);
         return(client.Uri.ToString());
     }
     catch (WebException e) {
         if (WebExceptionStatus.Timeout == e.Status)
         {
             // rethrow the error because if ran into a timeout issue then
             // we don't want the code to continue as there is not going to be any good
             // result if we can't return a valid url to the caller.
             throw;
         }
         // we are assuming here that we just got a 403 - Forbidden: Access is denied error
         // because we are navigating to the publish url of the Gallery Server so we simply
         // catch the error and return the response url of the response that can be used for publishing
         // the reason why we get this error is because this is a POST action and IIS gives us this error
         // because it things that we are trying to navigate to a page.
         return(e.Response.ResponseUri.ToString());
     }
 }
예제 #4
0
        private Uri ResolveBaseUrl()
        {
            Uri uri = null;

            try
            {
                var client = new RedirectedHttpClient(new Uri(Source));
                uri = client.Uri;
            }
            catch (WebException ex)
            {
                var response = (HttpWebResponse)ex.Response;
                if (response == null)
                {
                    throw;
                }

                uri = response.ResponseUri;
            }

            return EnsureTrailingSlash(uri);
        }
 private DataServicePackageRepository GetPackageRepository()
 {
     if (_packageRepository == null || _packageRepository.Source != _redirectedlPackageSource) {
         try {
             Uri packageUri = new Uri(PackageSource);
             IWebProxy packageSourceProxy = _proxyService.GetProxy(packageUri);
             IHttpClient packageSourceClient = new RedirectedHttpClient(packageUri, packageSourceProxy);
             _packageRepository = new DataServicePackageRepository(packageSourceClient);
             _redirectedlPackageSource = _packageRepository.Source;
         }
         catch (Exception) {
             _packageRepository = null;
         }
     }
     return _packageRepository;
 }