Exemple #1
0
 public WebException(string message, 
     Exception innerException,
     WebExceptionStatus status,
     HttpResponse response)
     : base(message, innerException)
 {
     this.status = status;
     this.response = response;
 }
Exemple #2
0
 private static void HttpResponseReceived(object sender, HttpResponse resp)
 {
     if (resp == null)
     {
         Debug.Print("Failed to parse response");
         return;
     }
     Debug.Print("==== Response received ================================");
     Debug.Print("Status : " + resp.StatusCode);
     Debug.Print("Reason : " + resp.Reason);
     foreach (var item in resp.Headers)
     {
         var key = ((DictionaryEntry)item).Key;
         var val = ((DictionaryEntry)item).Value;
         Debug.Print(key + " : " + val);
     }
     if (resp.Body != null && resp.Body.Length > 0)
     {
         Debug.Print("Body:");
         //Debug.Print(resp.Body);
     }
 }
Exemple #3
0
        internal bool OnResponseReceived(SocketReceivedDataEventArgs args)
        {
            // We got an unparsable reply, so ignore subsequent data packets
            if (_failed)
                return true;

            if (_response==null)
                _response = new HttpResponse();

            bool isComplete = false;
            try
            {
                isComplete = _response.ProcessResponse(args.Data);
            }
            catch (Exception)
            {
                _response = null;
                _failed = true;
                isComplete = true;
            }

            if (isComplete)
            {
                if (this.ResponseReceived != null)
                    this.ResponseReceived(this, _response);
                this.Reset();
            }

            return isComplete;
        }
Exemple #4
0
        private void SocketOnDataReceived(object sender, SocketReceivedDataEventArgs args)
        {
            if (_activeRequest == null)
                return;

            ISocket socket = (ISocket)sender;

            if (_activeRequest.OnResponseReceived(args))
            {
                _lastResponse = _activeRequest.Response;
                _activeRequest = null;
                // If this was an async send, we saved a ref to the socket.  Clean that up now.
                if (_socket!=null && _socket == socket)
                {
                    _socket.SocketClosed -= SocketOnSocketClosed;
                    _socket.DataReceived -= SocketOnDataReceived;
                    _socket.Dispose();
                    _socket = null;
                }
                _requestCompletedEvent.Set();
            }
        }
Exemple #5
0
 /// <summary>
 /// Reset the state of the request so that the request can be re-sent.
 /// You can change the body and headers after reset and before resending.
 /// </summary>
 public void Reset()
 {
     // Prepare for a re-send of the same request
     _failed = false;
     _response = null;
 }