Exemplo n.º 1
0
            private void WaitForResponse()
            {
                IAsyncResult asyncResult = this.request.BeginGetResponse((IAsyncResult res) => {
                    try
                    {
                        using (HttpWebResponse httpWebResponse = (HttpWebResponse)this.request.EndGetResponse(res))
                        {
                            using (Stream responseStream = httpWebResponse.GetResponseStream())
                            {
                                using (StreamReader streamReader = new StreamReader(responseStream))
                                {
                                    this.ResponseText = streamReader.ReadToEnd();
                                }
                            }
                            this.ResponseCode = (int)httpWebResponse.StatusCode;
                        }
                    }
                    catch (WebException webException1)
                    {
                        WebException webException = webException1;
                        this.ResponseText         = WebRequests.FormatWebException(webException, this.ResponseText ?? string.Empty);
                        HttpWebResponse response  = webException.Response as HttpWebResponse;
                        if (response != null)
                        {
                            try
                            {
                                using (Stream stream = response.GetResponseStream())
                                {
                                    using (StreamReader streamReader1 = new StreamReader(stream))
                                    {
                                        this.ResponseText = streamReader1.ReadToEnd();
                                    }
                                }
                            }
                            catch (Exception exception)
                            {
                            }
                            this.ResponseCode = (int)response.StatusCode;
                        }
                    }
                    catch (Exception exception2)
                    {
                        Exception exception1 = exception2;
                        this.ResponseText    = WebRequests.FormatWebException(exception1, this.ResponseText ?? string.Empty);
                        string str           = string.Concat("Web request produced exception (Url: ", this.Url, ")");
                        if (this.Owner)
                        {
                            str = string.Concat(str, string.Format(" in '{0} v{1}' plugin", this.Owner.Name, this.Owner.Version));
                        }
                        Interface.Oxide.LogException(str, exception1);
                    }
                    if (this.request == null)
                    {
                        return;
                    }
                    this.request.Abort();
                    this.OnComplete();
                }, null);

                this.waitHandle           = asyncResult.AsyncWaitHandle;
                this.registeredWaitHandle = ThreadPool.RegisterWaitForSingleObject(this.waitHandle, new WaitOrTimerCallback(this.OnTimeout), null, this.request.Timeout, true);
            }
Exemplo n.º 2
0
 public void Start()
 {
     try
     {
         this.request                                = (HttpWebRequest)System.Net.WebRequest.Create(this.Url);
         this.request.Method                         = this.Method;
         this.request.Credentials                    = CredentialCache.DefaultCredentials;
         this.request.Proxy                          = null;
         this.request.KeepAlive                      = false;
         this.request.Timeout                        = (int)Math.Round((double)((this.Timeout.Equals(0f) ? WebRequests.Timeout : this.Timeout) * 1000f));
         this.request.AutomaticDecompression         = (WebRequests.AllowDecompression ? DecompressionMethods.GZip | DecompressionMethods.Deflate : DecompressionMethods.None);
         this.request.ServicePoint.MaxIdleTime       = this.request.Timeout;
         this.request.ServicePoint.Expect100Continue = ServicePointManager.Expect100Continue;
         this.request.ServicePoint.ConnectionLimit   = ServicePointManager.DefaultConnectionLimit;
         if (!this.request.RequestUri.IsLoopback && Environment.OSVersion.Platform != PlatformID.Unix)
         {
             this.request.ServicePoint.BindIPEndPointDelegate = (ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount) => new IPEndPoint(WebRequests.covalence.Server.LocalAddress ?? WebRequests.covalence.Server.Address, 0);
         }
         byte[] bytes = new byte[0];
         if (this.Body != null)
         {
             bytes = Encoding.UTF8.GetBytes(this.Body);
             this.request.ContentLength = (long)((int)bytes.Length);
             this.request.ContentType   = "application/x-www-form-urlencoded";
         }
         if (this.RequestHeaders != null)
         {
             this.request.SetRawHeaders(this.RequestHeaders);
         }
         if (bytes.Length == 0)
         {
             this.WaitForResponse();
         }
         else
         {
             this.request.BeginGetRequestStream((IAsyncResult result) => {
                 if (this.request == null)
                 {
                     return;
                 }
                 try
                 {
                     using (Stream stream = this.request.EndGetRequestStream(result))
                     {
                         stream.Write(bytes, 0, (int)bytes.Length);
                     }
                 }
                 catch (Exception exception)
                 {
                     this.ResponseText = WebRequests.FormatWebException(exception, this.ResponseText ?? string.Empty);
                     HttpWebRequest u003cu003e4_this = this.request;
                     if (u003cu003e4_this != null)
                     {
                         u003cu003e4_this.Abort();
                     }
                     else
                     {
                     }
                     this.OnComplete();
                     return;
                 }
                 this.WaitForResponse();
             }, null);
         }
     }
     catch (Exception exception2)
     {
         Exception exception1 = exception2;
         this.ResponseText = WebRequests.FormatWebException(exception1, this.ResponseText ?? string.Empty);
         string str = string.Concat("Web request produced exception (Url: ", this.Url, ")");
         if (this.Owner)
         {
             str = string.Concat(str, string.Format(" in '{0} v{1}' plugin", this.Owner.Name, this.Owner.Version));
         }
         Interface.Oxide.LogException(str, exception1);
         HttpWebRequest httpWebRequest = this.request;
         if (httpWebRequest != null)
         {
             httpWebRequest.Abort();
         }
         else
         {
         }
         this.OnComplete();
     }
 }