Пример #1
0
        public void Send(RequestState requestState)
        {
            if (requestState == null)
            {
                return;
            }

            try
            {
                RequestSetting setting = requestState.Setting;
                SetHttpRequest(setting);

                requestState.Request = request;
                switch (setting.Method)
                {
                    case RequestMethod.POST:
                    case RequestMethod.PUT:
                    case RequestMethod.PATCH:
                        IAsyncResult getRequestResult = request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), requestState);
                        break;
                    case RequestMethod.OPTIONS:
                    case RequestMethod.HEAD:
                    case RequestMethod.GET:
                    case RequestMethod.DELETE:
                    case RequestMethod.TRACE:
                    case RequestMethod.CONNECT:
                    default:
                        IAsyncResult getResponseResult = request.BeginGetResponse(new AsyncCallback(GetResponseCallback), requestState);
                        break;
                }
            }
            catch(WebException webEx)
            {
                RaiseRequestException(requestState, webEx, null);
            }
            catch(Exception ex)
            {
                RaiseRequestException(requestState, null, ex);
            }
        }
Пример #2
0
        private void RaiseRequestOk(RequestState requestState)
        {
            Response response = new Response(requestState.HttpWebResponse.StatusCode, requestState.HttpWebResponse.StatusDescription,
                requestState.HttpWebResponse.Headers, requestState.ResponseMemoryStream.ToArray());

            requestState.RaiseRequestCompelete(requestState, new RequestCompeleteEventArgs(response));
        }
Пример #3
0
        static void TestUri(RequestMethod method, string uri, string postData)
        {
            var requestSetting = new RequestSetting(method, uri);
            requestSetting.PostData = Encoding.UTF8.GetBytes(postData);
            var requestState = new RequestState();
            requestState.Setting = requestSetting;
            requestState.Completed += new EventHandler<RequestCompeleteEventArgs>(RequestCompleted);

            var request = new Request();
            request.Send(requestState);
        }
Пример #4
0
        private void RaiseRequestException(RequestState requestState, WebException webEx, Exception ex)
        {
            RequestCompeleteEventArgs e = new RequestCompeleteEventArgs(true);
            if(webEx != null)
            {
                e.WebError = webEx;
            }
            if (ex != null)
            {
                e.ExtraError = ex;
            }

            requestState.RaiseRequestCompelete(requestState, e);
        }
Пример #5
0
        static void TestUri(RequestMethod method, string uri)
        {
            var requestSetting = new RequestSetting(method, uri);
            var requestState = new RequestState();
            requestState.Setting = requestSetting;
            requestState.Completed += new EventHandler<RequestCompeleteEventArgs>(RequestCompleted);

            var request = new Request();
            request.Send(requestState);
        }