Esempio n. 1
0
        public void Navigate(Uri requestUrl, HttpRequestContent content = null)
        {
            var arg = new ScriptingContext(requestUrl, content);

            Navigate(arg);
            arg.WaitHandle.WaitOne();
        }
Esempio n. 2
0
        public string GetHtml(Uri requestUrl, HttpRequestContent content = null)
        {
            var browser = webBrowser1;

            this.Navigate(requestUrl, content);
            return(CurrentGetHtml());
        }
Esempio n. 3
0
 public HttpClient(Uri url = null, Func <HttpWebResponse, bool> validateResponse = null)
 {
     _referer          = Default.OriginalString;
     _content          = new HttpRequestContent();
     _validateResponse = validateResponse;
     this.SetRequest(url ?? Default);
 }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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;
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
 public Stream GetStream(Uri requestUrl, HttpRequestContent content = null)
 {
     return(this.Client.GetStream(requestUrl, content));
 }
Esempio n. 8
0
 Stream IHttpClient.GetStream(Uri requestUrl, HttpRequestContent content)
 {
     Contract.Requires(requestUrl != null);
     Contract.Ensures(Contract.Result <Stream>() != null);
     return(default(Stream));
 }
Esempio n. 9
0
 string IHttpClient.GetHtml(Uri requestUrl, HttpRequestContent content)
 {
     Contract.Requires(requestUrl != null);
     Contract.Ensures(Contract.Result <string>() != null);
     return(default(string));
 }
Esempio n. 10
0
 public void Navigate(Uri requestUrl, HttpRequestContent content = null)
 {
     Call(CallPack.ActionName.Navigate, new object[] { requestUrl, content });
 }