Esempio n. 1
0
        public void Send()
        {
            CHttpRequestState requestState = new CHttpRequestState();

            requestState.Request = webRequest;

            if (requestBytes != null)
            {
                webRequest.BeginGetRequestStream(RequestStreamData, requestState);
            }
            else
            {
                webRequest.BeginGetResponse(ReceivedData, requestState);
            }
        }
Esempio n. 2
0
        private void ReceivedData(IAsyncResult asyncResult)
        {
            try
            {
                CHttpRequestState requestState = (CHttpRequestState)asyncResult.AsyncState;

                HttpWebRequest httpWebRequest = requestState.Request;

                requestState.Response = (HttpWebResponse)httpWebRequest.EndGetResponse(asyncResult);
                Stream responseStream = requestState.Response.GetResponseStream();
                requestState.StreamResponse = responseStream;

                IAsyncResult asynchronousInputRead = responseStream.BeginRead(requestState.BufferRead, 0, CHttpRequestState.BUFFER_SIZE, new AsyncCallback(ReadCallBack), requestState);
            }catch (Exception ex)
            {
                error        = ex.Message;
                isDone       = true;
                isError      = true;
                responseCode = 0;
            }
        }
Esempio n. 3
0
        private void RequestStreamData(IAsyncResult asyncResult)
        {
            try
            {
                CHttpRequestState requestState   = (CHttpRequestState)asyncResult.AsyncState;
                HttpWebRequest    httpWebRequest = requestState.Request;

                var stream = httpWebRequest.EndGetRequestStream(asyncResult);
                stream.Write(requestBytes, 0, requestBytes.Length);
                stream.Close();

                webRequest.BeginGetResponse(ReceivedData, requestState);
            }
            catch (Exception ex)
            {
                error        = ex.Message;
                isDone       = true;
                isError      = true;
                responseCode = 0;
            }
        }
Esempio n. 4
0
        private void ReadCallBack(IAsyncResult asyncResult)
        {
            try
            {
                CHttpRequestState requestState   = (CHttpRequestState)asyncResult.AsyncState;
                Stream            responseStream = requestState.StreamResponse;
                int read = responseStream.EndRead(asyncResult);

                if (read > 0)
                {
                    responseLst.AddRange(requestState.BufferRead);
                    IAsyncResult asynchronousResult = responseStream.BeginRead(requestState.BufferRead, 0, CHttpRequestState.BUFFER_SIZE, new AsyncCallback(ReadCallBack), requestState);
                }
                else
                {
                    responseCode  = (int)requestState.Response.StatusCode;
                    responseBytes = responseLst.ToArray();
                    responseLst.Clear();
                    responseLst = null;
                    isDone      = true;
                    isError     = false;
                    if (responseCode < 200 || responseCode >= 300)
                    {
                        isError = true;
                    }
                    responseStream.Close();
                }
            }
            catch (Exception ex)
            {
                error        = ex.Message;
                isDone       = true;
                isError      = true;
                responseCode = 0;
            }
        }