Esempio n. 1
0
 public override IAsyncResult BeginSend(string url, HttpMessage.Request reqMsg, AsyncCallback callBack, object state)
 {
     var request = (HttpWebRequest)WebRequest.Create(url);
     request.CookieContainer = this.CookieContainer;
     foreach (var key in reqMsg.Headers.AllKeys)
     {
         switch (key)
         {
             case "Content-Type":
                 request.ContentType = reqMsg.Headers[key];
                 break;
             case "Content-Length":
                 request.ContentLength = long.Parse(reqMsg.Headers[key]);
                 break;
             case "Referer":
                 request.Referer = reqMsg.Headers[key];
                 break;
             default:
                 request.Headers.Add(key, reqMsg.Headers[key]);
                 break;
         }
     }
     request.Method = reqMsg.Method;
     var asyncResult = new AsyncResult(state, reqMsg, request, callBack);
     if (request.Method == "GET")
     {
         request.BeginGetResponse(this.OnGetResponse, asyncResult);
     }
     else
     {
         request.BeginGetRequestStream(this.OnGetRequestStream, asyncResult);
     }
     return asyncResult;
 }
Esempio n. 2
0
 public AsyncResult(object asyncState, HttpMessage.Request reqMsg, WebRequest webRequest, AsyncCallback callBack)
     : base(callBack, asyncState, reqMsg)
 {
     this.Request = webRequest;
 }
Esempio n. 3
0
 public AsyncResult(AsyncCallback callBack, object asyncState, HttpMessage.Request requestMessage, string url)
     : base(callBack, asyncState, requestMessage)
 {
     this.Client = new TcpClient();
     this.Uri = new Uri(url);
     this.RequestStreamStart = requestMessage.Stream != null
                                   ? requestMessage.Stream.Position
                                   : 0;
 }
Esempio n. 4
0
 public void OnComplete(HttpMessage.Response res)
 {
     this.Finish(res);
 }
Esempio n. 5
0
 public override IAsyncResult BeginSend(string url, HttpMessage.Request request, AsyncCallback callBack, object state)
 {
     var res = new AsyncResult(callBack, state, request, url);
     var uri = res.Uri;
     res.Client.BeginConnect(uri.DnsSafeHost, uri.IsDefaultPort ? 80 : uri.Port, this.OnClientConnect, res);
     return res;
 }
Esempio n. 6
0
 protected void Finish(HttpMessage.Response respMsg)
 {
     this.ResponseMessage = respMsg;
     this.IsCompleted = true;
     this.handle.Set();
     if (this.CallBack != null) this.CallBack(this);
 }
Esempio n. 7
0
 protected AsyncResultBase(AsyncCallback callBack, object asyncState, HttpMessage.Request requestMessage)
 {
     this.CallBack = callBack;
     AsyncState = asyncState;
     RequestMessage = requestMessage;
     this.handle = new ManualResetEvent(false);
 }
Esempio n. 8
0
 public HttpMessage.Response Send(string url, HttpMessage.Request request)
 {
     var asyncState = this.BeginSend(url, request, null, null);
     return this.EndSend(asyncState);
 }
Esempio n. 9
0
 public abstract IAsyncResult BeginSend(string url, HttpMessage.Request request, AsyncCallback callBack, object state);