public void Navigate(Uri requestUrl, HttpRequestContent content = null) { var arg = new ScriptingContext(requestUrl, content); Navigate(arg); arg.WaitHandle.WaitOne(); }
public string GetHtml(Uri requestUrl, HttpRequestContent content = null) { var browser = webBrowser1; this.Navigate(requestUrl, content); return(CurrentGetHtml()); }
public HttpClient(Uri url = null, Func <HttpWebResponse, bool> validateResponse = null) { _referer = Default.OriginalString; _content = new HttpRequestContent(); _validateResponse = validateResponse; this.SetRequest(url ?? Default); }
public ScriptingContext(Uri url, HttpRequestContent content) { this.RequestUrl = url; this.RequestContent = content; string ablock; if (this.RequestContent != null && this.RequestContent.Form != null) { if (!string.IsNullOrEmpty(ablock = this.RequestContent.Form.Get(AjaxBlockEntity.AjaxBlock))) { this.AjaxBlocks = (AjaxBlockEntity[])Serializer.Deserialize(new MemoryStream(Convert.FromBase64String(ablock))); this.RequestContent.Form.Remove(AjaxBlockEntity.AjaxBlock); } } this.WaitHandle = new AutoResetEvent(false); }
public void Navigate(Uri requestUrl, HttpRequestContent content = null) { var arg = new ScriptingContext(requestUrl, content); var browser = webBrowser1; browser.ObjectForScripting = arg; byte[] postData = null; string headers = null; if (arg.RequestContent != null) { if (this.UseCookies) { if (arg.RequestContent.HasCookie) { _cookieContainer.Add(arg.RequestUrl, arg.RequestContent.Cookies); } string cookieHeader = arg.RequestContent.Headers[HttpRequestHeader.Cookie]; if (!string.IsNullOrEmpty(cookieHeader)) { _cookieContainer.SetCookies(arg.RequestUrl, cookieHeader.Replace(';', ',')); arg.RequestContent.Headers.Remove(HttpRequestHeader.Cookie); } cookieHeader = _cookieContainer.GetCookieHeader(arg.RequestUrl); if (cookieHeader.Length > 0) { arg.RequestContent.Headers[HttpRequestHeader.Cookie] = cookieHeader.Replace(',', ';'); } //WinInetInterop.SaveCookies(_cookieContainer, absoluteUri); } else { arg.RequestContent.Headers[HttpRequestHeader.Cookie] = string.Empty; //WinInetInterop.DeleteCache(WinInetInterop.CacheKind.Cookies); } if (arg.RequestContent.HasBody) { arg.RequestContent.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; postData = Encoding.UTF8.GetBytes(arg.RequestContent.GetFormString()); } headers = arg.RequestContent.GetHeadersString(); } browser.Navigate(arg.RequestUrl, "_self", postData, headers); TaskHelper.Factory.StartNew(this.STA_WaitSr, browser); this.Tag = arg; }
Stream IHttpClient.GetStream(Uri requestUrl, HttpRequestContent content) { var client = (IHttpClient)this; Stream result = null; var waitDuration = client.RetryWaitDuration; App.Retry(() => { this.SetRequest(requestUrl); if (content != null) { this._content = content; } var res = this.GetResponse(); result = res.GetResponseStream(); }, client.RetryCount.GetValueOrDefault(1), waitDuration.HasValue ? (int)waitDuration.Value.TotalMilliseconds : 0); return(result); }
public Stream GetStream(Uri requestUrl, HttpRequestContent content = null) { return(this.Client.GetStream(requestUrl, content)); }
Stream IHttpClient.GetStream(Uri requestUrl, HttpRequestContent content) { Contract.Requires(requestUrl != null); Contract.Ensures(Contract.Result <Stream>() != null); return(default(Stream)); }
string IHttpClient.GetHtml(Uri requestUrl, HttpRequestContent content) { Contract.Requires(requestUrl != null); Contract.Ensures(Contract.Result <string>() != null); return(default(string)); }
public void Navigate(Uri requestUrl, HttpRequestContent content = null) { Call(CallPack.ActionName.Navigate, new object[] { requestUrl, content }); }