private string GetRequestHtml(string URL, Encoding EnCodeing, ReqMethod RMethod) { string html = string.Empty; try { req = (HttpWebRequest)WebRequest.Create(URL); req.AllowAutoRedirect = true; req.CookieContainer = cookieCon; req.Credentials = CredentialCache.DefaultCredentials; req.Method = RMethod.ToString(); req.ContentType = "application/x-www-form-urlencoded"; req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB5; Mozilla/4.0(Compatible Mozilla/4.0(Compatible-EmbeddedWB 14.59 http://bsalsa.com/ EmbeddedWB- 14.59 from: http://bsalsa.com/ ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30618; CIBA)"; res = (HttpWebResponse)req.GetResponse(); if (cookieheader.Equals(string.Empty)) { cookieheader = req.CookieContainer.GetCookieHeader(new Uri(URL)); } else { req.CookieContainer.SetCookies(new Uri(URL), cookieheader); } html = new StreamReader(res.GetResponseStream(), EnCodeing).ReadToEnd(); } catch (Exception ex) { html = ex.Message; } return(html); }
public RequestLineInfo(string reqLine) { var temp = reqLine.Split(new string[] { " " }, StringSplitOptions.None); if (temp.Length != 3) { throw new RequestLineParseException(reqLine, "请求行格式错误"); } switch (temp[0].ToUpper()) { case "GET": RequestMethod = ReqMethod.GET; break; case "POST": RequestMethod = ReqMethod.POST; break; case "HEAD": RequestMethod = ReqMethod.HEAD; break; default: throw new RequestLineParseException(reqLine, "reqMethod解析错误"); } ReqURL = new Uri(temp[1]); HttpVersion = temp[2]; }
public void onUireqtypeSelChenged(object sender, SelectionChangedEventArgs e) { string selectedContent = ((ComboBoxItem)ui_req_type.SelectedItem).Content.ToString(); if (selectedContent == "POST") { Console.WriteLine("POST"); _reqMethod = ReqMethod.POST; } if (selectedContent == "GET") { Console.WriteLine("GET"); _reqMethod = ReqMethod.GET; } }
private string GetRequestHtml(string URL, Encoding EnCodeing, ReqMethod RMethod) { string html = string.Empty; try { req = (HttpWebRequest)WebRequest.Create(URL); req.AllowAutoRedirect = true; req.CookieContainer = cookieCon; req.Credentials = CredentialCache.DefaultCredentials; req.Method = RMethod.ToString(); req.ContentType = "application/x-www-form-urlencoded"; req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB5; Mozilla/4.0(Compatible Mozilla/4.0(Compatible-EmbeddedWB 14.59 http://bsalsa.com/ EmbeddedWB- 14.59 from: http://bsalsa.com/ ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30618; CIBA)"; res = (HttpWebResponse)req.GetResponse(); if (cookieheader.Equals(string.Empty)) { cookieheader = req.CookieContainer.GetCookieHeader(new Uri(URL)); } else { req.CookieContainer.SetCookies(new Uri(URL), cookieheader); } html = new StreamReader(res.GetResponseStream(), EnCodeing).ReadToEnd(); } catch (Exception ex) { html = ex.Message; } return html; }