private void ReadResponseStream(IHttpWebRequest httpWebRequest, IHttpWebResponse httpWebResponse, Exception innerException, Stream responseSaveStream, AsyncCallback callback, object state) { Stream responseStream = null; Exception exception = null; try { responseStream = httpWebResponse.GetResponseStream(); } catch (WebException ex) { exception = new WebExceptionWrapper(ex); } catch (Exception ex) { exception = ex; } finally { if (exception == null) { CopyResponseStream(httpWebRequest, httpWebResponse, innerException, responseStream, responseSaveStream, callback, state); } else { if (callback != null) { callback(new HttpWebHelperResult(httpWebRequest, httpWebResponse, exception, null, false, false, responseSaveStream, state)); } } } }
private HttpWebHelperResult ReadResponseStream(IHttpWebRequest httpWebRequest, IHttpWebResponse httpWebResponse, Exception innerException, Stream responseSaveStream) { Stream responseStream = null; Exception exception = null; try { responseStream = httpWebResponse.GetResponseStream(); } catch (WebException ex) { exception = new WebExceptionWrapper(ex); } return(exception == null?CopyResponseStream(httpWebRequest, httpWebResponse, innerException, responseStream, responseSaveStream) : new HttpWebHelperResult(httpWebRequest, httpWebResponse, exception, innerException, false, true, responseSaveStream, null)); }
private void RequestCallback(IAsyncResult asyncResult, IHttpWebRequest httpWebRequest, Stream requestBody, AsyncCallback callback, object state) { Stream requestStream = null; Exception exception = null; IHttpWebResponse httpWebResponse = null; try { requestStream = httpWebRequest.EndGetRequestStream(asyncResult); } catch (WebException ex) { var webException = new WebExceptionWrapper(ex); httpWebResponse = webException.GetResponse(); exception = webException; } finally { if (exception == null) { // we got the stream, so copy to the stream CopyRequestStream(httpWebRequest, requestBody, requestStream, callback, state); } else { // there was an error if (httpWebResponse == null) { if (callback != null) { callback(new HttpWebHelperResult(httpWebRequest, null, exception, null, false, false, null, state)); } } else { var args = new ResponseReceivedEventArgs(httpWebResponse, exception, state); OnResponseReceived(args); ReadResponseStream(httpWebRequest, httpWebResponse, exception, args.ResponseSaveStream, callback, state); } } } }
private HttpWebHelperResult WriteAndGetReponse(IHttpWebRequest httpWebRequest, Stream requestBody) { Stream requestStream = null; Exception exception = null; IHttpWebResponse httpWebResponse = null; HttpWebHelperResult result; try { requestStream = httpWebRequest.GetRequestStream(); } catch (WebException ex) { var webException = new WebExceptionWrapper(ex); httpWebResponse = webException.GetResponse(); exception = webException; } finally { if (exception == null) { // we got the stream, so copy to the stream result = CopyRequestStream(httpWebRequest, requestBody, requestStream); } else { // there was an error if (httpWebResponse == null) { result = new HttpWebHelperResult(httpWebRequest, null, exception, null, false, true, null, null); } else { var args = new ResponseReceivedEventArgs(httpWebResponse, exception, null); OnResponseReceived(args); result = ReadResponseStream(httpWebRequest, httpWebResponse, exception, args.ResponseSaveStream); } } } return(result); }
private void ResponseCallback(IAsyncResult asyncResult, IHttpWebRequest httpWebRequest, Stream requestBody, AsyncCallback callback, object state) { IHttpWebResponse httpWebResponse = null; Exception exception = null; try { httpWebResponse = httpWebRequest.EndGetResponse(asyncResult); } catch (WebException ex) { var webException = new WebExceptionWrapper(ex); httpWebResponse = webException.GetResponse(); exception = webException; } catch (Exception ex) { exception = ex; } finally { if (httpWebResponse != null) { var args = new ResponseReceivedEventArgs(httpWebResponse, exception, state); OnResponseReceived(args); ReadResponseStream(httpWebRequest, httpWebResponse, exception, args.ResponseSaveStream, callback, state); } else { if (callback != null) { callback(new HttpWebHelperResult(httpWebRequest, httpWebResponse, exception, null, false, false, null, state)); } } } }
private HttpWebHelperResult GetResponse(IHttpWebRequest httpWebRequest, Stream requestBody) { IHttpWebResponse httpWebResponse = null; Exception exception = null; HttpWebHelperResult httpWebHelperAsyncResult = null; try { httpWebResponse = httpWebRequest.GetResponse(); } catch (WebException ex) { var webException = new WebExceptionWrapper(ex); httpWebResponse = webException.GetResponse(); exception = webException; } catch (Exception ex) { exception = ex; } finally { if (httpWebResponse != null) { var args = new ResponseReceivedEventArgs(httpWebResponse, exception, null); OnResponseReceived(args); httpWebHelperAsyncResult = ReadResponseStream(httpWebRequest, httpWebResponse, exception, args.ResponseSaveStream); } else { httpWebHelperAsyncResult = new HttpWebHelperResult(httpWebRequest, httpWebResponse, exception, null, false, true, null, null); } } return(httpWebHelperAsyncResult); }