当前位置: 首页>>代码示例>>C#>>正文


C# Request.SetRedirectUrl方法代码示例

本文整理汇总了C#中System.Net.Request.SetRedirectUrl方法的典型用法代码示例。如果您正苦于以下问题:C# Request.SetRedirectUrl方法的具体用法?C# Request.SetRedirectUrl怎么用?C# Request.SetRedirectUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Request的用法示例。


在下文中一共展示了Request.SetRedirectUrl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PerformRequest

        /// <summary>
        /// ����������
        /// �������ײ�����Ĵ���
        /// </summary>
        public NetworkResponse PerformRequest(Request request)
        {
            long requestStart = SystemClock.ElapsedRealtime();
            while (true)
            {
                HttpWebResponse httpResponse = null;
                byte[] responseContents = null;
                Dictionary<String,String> responseHeaders = null;
                try
                {
                    Dictionary<String, String> headers = new Dictionary<string, string>();
                    AddCacheHeaders(headers, request.CacheEntry);

                    //��������
                    httpResponse = mHttpStack.PerformRequest(request, headers);

                    var statusCode = httpResponse.StatusCode;
                    responseHeaders = ConvertHeaders(httpResponse.Headers);

                    if (statusCode == HttpStatusCode.MovedPermanently || statusCode == HttpStatusCode.Moved)
                    {
                        String newUrl = responseHeaders["Location"];
                        request.SetRedirectUrl(newUrl);
                    }

                    //��ȡ���󵽵�����
                    Stream output = httpResponse.GetResponseStream();
                    if (output != null)
                    {
                        responseContents = EntityToBytes(output);
                    }
                    else
                    {
                        responseContents = new byte[0];
                    }

                    long requestLifetime = SystemClock.ElapsedRealtime() - requestStart;
                    LogSlowRequests(requestLifetime, request, responseContents, statusCode);

                    if (statusCode < HttpStatusCode.OK || (int)statusCode > 299)
                    {
                        throw new IOException();
                    }
                    return new NetworkResponse(statusCode, responseContents, responseHeaders, false,
                        SystemClock.ElapsedRealtime() - requestStart);
                }
                catch (WebException ex)
                {
                    if (ex.Response != null)
                    {
                        var result = ex.Response as HttpWebResponse;
                        if (result.StatusCode == HttpStatusCode.NotModified)
                        {
                            Entry entry = request.CacheEntry;
                            if (entry == null)
                            {
                                return new NetworkResponse(HttpStatusCode.NotModified, null,
                                    responseHeaders, true,
                                    SystemClock.ElapsedRealtime() - requestStart);
                            }
                            //entry.ResponseHeaders = entry.ResponseHeaders.Intersect(responseHeaders).ToDictionary(x => x.Key, x => x.Value);
                            return new NetworkResponse(HttpStatusCode.NotModified, entry.Data,
                                entry.ResponseHeaders, true,
                                SystemClock.ElapsedRealtime() - requestStart);
                        }
                    }
                    throw new NetworkError(ex);
                }
                catch (TimeoutException)
                {
                    AttempRetryOnException("connection", request, new TimeoutError());
                }
                catch (IOException e)
                {
                    HttpStatusCode statusCode = 0;
                    NetworkResponse networkResponse = null;
                    if (httpResponse != null)
                    {
                        statusCode = httpResponse.StatusCode;
                    }
                    else
                    {
                        throw new NoConnectionError(e);
                    }
                    if (statusCode == HttpStatusCode.MovedPermanently)
                    {
                        VolleyLog.E("Request at {0} has been redirected to {1}", request.OriginUrl, request.Url);
                    }
                    else
                    {
                        VolleyLog.E("Unexpected response code {0} for {1}", statusCode, request.Url);
                    }
                    if (responseContents != null)
                    {
                        networkResponse = new NetworkResponse(statusCode, responseContents,
                            responseHeaders, false, SystemClock.ElapsedRealtime() - requestStart);
//.........这里部分代码省略.........
开发者ID:huguodong,项目名称:Volley-For-Xamarin-Android,代码行数:101,代码来源:BasicNetwork.cs

示例2: PerformRequest

 public HttpWebResponse PerformRequest(Request request, Dictionary<string, string> additionalHeaders)
 {
     if (UrlRewriter != null)
     {
         String rewritten = UrlRewriter.RewriteUrl(request.Url);
         if (!String.IsNullOrEmpty(rewritten))
         {
             request.SetRedirectUrl(rewritten);
         }
     }
     var httpRequest = CreateHttpRequest(request);
     foreach (KeyValuePair<String, String> head in additionalHeaders)
     {
         try
         {
             httpRequest.Headers.Add(head.Key, head.Value);
         }
         catch (Exception)
         {
             continue;
         }
     }
     foreach (KeyValuePair<String, String> head in request.GetHeaders())
     {
         try
         {
             httpRequest.Headers.Add(head.Key, head.Value);
         }
         catch (Exception)
         {
             continue;
         }
     }
     return (HttpWebResponse)httpRequest.GetResponse();
 }
开发者ID:huguodong,项目名称:Volley-For-Xamarin-Android,代码行数:35,代码来源:HttpClientStack.cs


注:本文中的System.Net.Request.SetRedirectUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。