示例#1
0
        protected void MakeRequest()
        {
            // 授权请求
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url is empty");
            }

            try
            {
                /*
                 * Create new Request
                 */
                HttpWebRequest request = this.GetWebRequest(url);
                request.CookieContainer = Cookies.Container;
                request.Method          = method.ToString().ToUpper();
                if (headers != null)
                {
                    request.Headers = GetHeadersFromProvider(headers.GetHeaders());
                }

                if (body != null)
                {
                    byte[] data = body.getBodyParameter();
                    request.ContentType = body.GetContentType();
                    using (Stream stream = request.GetRequestStream())
                    {
                        stream.Write(data, 0, data.Length);
                    }
                }
                if (sync)
                {
                    ExecuteSyncRequest(request);
                }
                else
                {
                    ExecuteRequest(request);
                }
            }
            catch (WebException webEx)
            {
                action.Fail(webEx);
            }
        }