示例#1
0
        private static void BeginRequest(IAsyncResult ar)
        {
            HttpCommunicator communicator = ar.AsyncState as HttpCommunicator;

            if (communicator != null)
            {
                Stream stream = communicator.Request.EndGetRequestStream(ar);
                if (stream != null)
                {
                    if (communicator.Buffer != null && communicator.Buffer.Length > 0)
                    {
                        stream.Write(communicator.Buffer, 0, communicator.Buffer.Length);
                    }
                    stream.Close();
                }
                communicator.Request.BeginGetResponse(new AsyncCallback(HttpCommunicator.BeginResponse), communicator);
            }
        }
示例#2
0
        private static void BeginResponse(IAsyncResult ar)
        {
            HttpCommunicator communicator = ar.AsyncState as HttpCommunicator;

            if (communicator != null)
            {
                HttpWebResponse response = (HttpWebResponse)communicator.Request.EndGetResponse(ar);
                if (response != null)
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        Stream stream = response.GetResponseStream();
                        if (stream != null)
                        {
                            byte[] buffer = new byte[(int)stream.Length];
                            stream.Read(buffer, 0, (int)stream.Length);
                            RdlTagCollection tags = RdlTagCollection.FromBytes(buffer);
                            CommunicatorResponseEventArgs args = new CommunicatorResponseEventArgs(communicator, tags);

                            if (communicator.AltCallback != null)
                            {
                                communicator.AltCallback(args);
                            }
                            else
                            {
                                communicator.Response(args);
                            }
                            stream.Close();
                        }
                    }
                    else
                    {
                        communicator.Failed(new CommunicatorEventArgs(communicator));
                    }
                }
            }
        }