Example #1
0
        /// <summary>
        /// 获取响应数据
        /// </summary>
        /// <returns>响应数据</returns>
        private HttpWebRequestResponse GetWebRequestResponse()
        {
            var webRequest      = new System.Net.HttpWebRequest(new Uri(uri));
            var requestResponse = new HttpWebRequestResponse(webRequest);

            webRequest.Method = method.ToString();

            webRequest.KeepAlive = false;

            if (cookieContainer != null)
            {
                webRequest.CookieContainer = cookieContainer;
            }

            if (headers != null)
            {
                foreach (var kv in headers)
                {
                    webRequest.Headers.Add(kv.Key, kv.Value);
                }
            }

            if (requestBytes != null)
            {
                if (method != Restfuls.Delete)
                {
                    webRequest.ContentType   = contentType;
                    webRequest.ContentLength = requestBytes.Length;
                    requestResponse.SetRequestBytes(requestBytes);
                }
            }

            if (timeout > 0)
            {
                webRequest.Timeout = timeout;
            }

            if (readWriteTimeout > 0)
            {
                webRequest.ReadWriteTimeout = readWriteTimeout;
            }

            requestResponse.Send();
            return(requestResponse);
        }
Example #2
0
 public IEnumerator Send()
 {
     return(response = GetWebRequestResponse());
 }
Example #3
0
 public IEnumerator Send()
 {
     return response = GetWebRequestResponse();
 }
Example #4
0
        private HttpWebRequestResponse GetWebRequestResponse()
        {
            var webRequest = new System.Net.HttpWebRequest(new Uri(uri));
            var requestResponse = new HttpWebRequestResponse(webRequest);
            webRequest.Method = method.ToString();

            webRequest.KeepAlive = false;

            if (cookieContainer != null)
            {
                webRequest.CookieContainer = cookieContainer;
            }

            if (headers != null)
            {
                headers.Walk(webRequest.Headers.Add);
            }

            if (requestBytes != null)
            {
                if (method != ERestful.DELETE)
                {
                    webRequest.ContentType = contentType;
                    webRequest.ContentLength = requestBytes.Length;
                    requestResponse.SetRequestBytes(requestBytes);
                }
            }

            if(timeout > 0)
            {
                webRequest.Timeout = timeout;
            }

            if(readWriteTimeout > 0)
            {
                webRequest.ReadWriteTimeout = readWriteTimeout;
            }

            requestResponse.Send();
            return requestResponse;
        }