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; }
public AsyncResult(object asyncState, HttpMessage.Request reqMsg, WebRequest webRequest, AsyncCallback callBack) : base(callBack, asyncState, reqMsg) { this.Request = webRequest; }
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; }
public void OnComplete(HttpMessage.Response res) { this.Finish(res); }
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; }
protected void Finish(HttpMessage.Response respMsg) { this.ResponseMessage = respMsg; this.IsCompleted = true; this.handle.Set(); if (this.CallBack != null) this.CallBack(this); }
protected AsyncResultBase(AsyncCallback callBack, object asyncState, HttpMessage.Request requestMessage) { this.CallBack = callBack; AsyncState = asyncState; RequestMessage = requestMessage; this.handle = new ManualResetEvent(false); }
public HttpMessage.Response Send(string url, HttpMessage.Request request) { var asyncState = this.BeginSend(url, request, null, null); return this.EndSend(asyncState); }
public abstract IAsyncResult BeginSend(string url, HttpMessage.Request request, AsyncCallback callBack, object state);