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


C# HttpRequestMessage.IsAborted方法代码示例

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


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

示例1: ExecuteRequest

 protected internal virtual void ExecuteRequest(HttpClient httpClient, HttpRequestMessage
      request)
 {
     object fullBody = null;
     Exception error = null;
     HttpResponse response = null;
     try
     {
         Log.V(Log.TagSync, "%s: RemoteRequest executeRequest() called, url: %s", this, url
             );
         if (request.IsAborted())
         {
             Log.V(Log.TagSync, "%s: RemoteRequest has already been aborted", this);
             RespondWithResult(fullBody, new Exception(string.Format("%s: Request %s has been aborted"
                 , this, request)), response);
             return;
         }
         Log.V(Log.TagSync, "%s: RemoteRequest calling httpClient.execute", this);
         response = httpClient.Execute(request);
         Log.V(Log.TagSync, "%s: RemoteRequest called httpClient.execute", this);
         // add in cookies to global store
         try
         {
             if (httpClient is DefaultHttpClient)
             {
                 DefaultHttpClient defaultHttpClient = (DefaultHttpClient)httpClient;
                 this.clientFactory.AddCookies(defaultHttpClient.GetCookieStore().GetCookies());
             }
         }
         catch (Exception e)
         {
             Log.E(Log.TagRemoteRequest, "Unable to add in cookies to global store", e);
         }
         StatusLine status = response.GetStatusLine();
         if (Utils.IsTransientError(status) && RetryRequest())
         {
             return;
         }
         if (status.GetStatusCode() >= 300)
         {
             Log.E(Log.TagRemoteRequest, "Got error status: %d for %s.  Reason: %s", status.GetStatusCode
                 (), request, status.GetReasonPhrase());
             error = new HttpResponseException(status.GetStatusCode(), status.GetReasonPhrase(
                 ));
         }
         else
         {
             HttpEntity temp = response.GetEntity();
             if (temp != null)
             {
                 InputStream stream = null;
                 try
                 {
                     stream = temp.GetContent();
                     fullBody = Manager.GetObjectMapper().ReadValue<object>(stream);
                 }
                 finally
                 {
                     try
                     {
                         stream.Close();
                     }
                     catch (IOException)
                     {
                     }
                 }
             }
         }
     }
     catch (IOException e)
     {
         Log.E(Log.TagRemoteRequest, "io exception", e);
         error = e;
         // Treat all IOExceptions as transient, per:
         // http://hc.apache.org/httpclient-3.x/exception-handling.html
         Log.V(Log.TagSync, "%s: RemoteRequest calling retryRequest()", this);
         if (RetryRequest())
         {
             return;
         }
     }
     catch (Exception e)
     {
         Log.E(Log.TagRemoteRequest, "%s: executeRequest() Exception: ", e, this);
         error = e;
     }
     Log.V(Log.TagSync, "%s: RemoteRequest calling respondWithResult.  error: %s", this
         , error);
     RespondWithResult(fullBody, error, response);
 }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:90,代码来源:RemoteRequest.cs

示例2: ExecuteRequest

 protected internal override void ExecuteRequest(HttpClient httpClient, HttpRequestMessage
      request)
 {
     object fullBody = null;
     Exception error = null;
     HttpResponse response = null;
     try
     {
         if (request.IsAborted())
         {
             RespondWithResult(fullBody, new Exception(string.Format("%s: Request %s has been aborted"
                 , this, request)), response);
             return;
         }
         response = httpClient.Execute(request);
         try
         {
             // add in cookies to global store
             if (httpClient is DefaultHttpClient)
             {
                 DefaultHttpClient defaultHttpClient = (DefaultHttpClient)httpClient;
                 this.clientFactory.AddCookies(defaultHttpClient.GetCookieStore().GetCookies());
             }
         }
         catch (Exception e)
         {
             Log.E(Log.TagRemoteRequest, "Unable to add in cookies to global store", e);
         }
         StatusLine status = response.GetStatusLine();
         if (status.GetStatusCode() >= 300)
         {
             Log.E(Log.TagRemoteRequest, "Got error status: %d for %s.  Reason: %s", status.GetStatusCode
                 (), request, status.GetReasonPhrase());
             error = new HttpResponseException(status.GetStatusCode(), status.GetReasonPhrase(
                 ));
         }
         else
         {
             HttpEntity entity = response.GetEntity();
             Header contentTypeHeader = entity.GetContentType();
             InputStream inputStream = null;
             if (contentTypeHeader != null && contentTypeHeader.GetValue().Contains("multipart/related"
                 ))
             {
                 try
                 {
                     MultipartDocumentReader reader = new MultipartDocumentReader(response, db);
                     reader.SetContentType(contentTypeHeader.GetValue());
                     inputStream = entity.GetContent();
                     int bufLen = 1024;
                     byte[] buffer = new byte[bufLen];
                     int numBytesRead = 0;
                     while ((numBytesRead = inputStream.Read(buffer)) != -1)
                     {
                         if (numBytesRead != bufLen)
                         {
                             byte[] bufferToAppend = Arrays.CopyOfRange(buffer, 0, numBytesRead);
                             reader.AppendData(bufferToAppend);
                         }
                         else
                         {
                             reader.AppendData(buffer);
                         }
                     }
                     reader.Finish();
                     fullBody = reader.GetDocumentProperties();
                     RespondWithResult(fullBody, error, response);
                 }
                 finally
                 {
                     try
                     {
                         inputStream.Close();
                     }
                     catch (IOException)
                     {
                     }
                 }
             }
             else
             {
                 if (entity != null)
                 {
                     try
                     {
                         inputStream = entity.GetContent();
                         fullBody = Manager.GetObjectMapper().ReadValue<object>(inputStream);
                         RespondWithResult(fullBody, error, response);
                     }
                     finally
                     {
                         try
                         {
                             inputStream.Close();
                         }
                         catch (IOException)
                         {
                         }
                     }
                 }
//.........这里部分代码省略.........
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:101,代码来源:RemoteMultipartDownloaderRequest.cs


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