C# 如何像java apache httpclient那样使用Asp.net 1.1 webrequest?
我是asp.net新手,我的服务器中有asp.net 1.1。C# 如何像java apache httpclient那样使用Asp.net 1.1 webrequest?,c#,java,asp.net,parsing,C#,Java,Asp.net,Parsing,我是asp.net新手,我的服务器中有asp.net 1.1。 我想在后台-->登录到另一个站点并在其中导航为什么要使用12年前的框架版本?您正在寻找CookieContainer,而HtmlAgilityPack.CookieContainer在我的情况下不起作用。我做错了什么?将您的请求与来自Fiddler中真实浏览器的请求进行比较,看看有什么不同。现在我可以登录和导航了,在示例中,类似的登录是错误的。所缺少的是获得一个验证码给用户,用户将键入验证码,然后在后台执行该过程。可能吗? pro
我想在后台-->登录到另一个站点并在其中导航为什么要使用12年前的框架版本?您正在寻找
CookieContainer
,而HtmlAgilityPack.CookieContainer在我的情况下不起作用。我做错了什么?将您的请求与来自Fiddler中真实浏览器的请求进行比较,看看有什么不同。现在我可以登录和导航了,在示例中,类似的登录是错误的。所缺少的是获得一个验证码给用户,用户将键入验证码,然后在后台执行该过程。可能吗?
protected void Page_Load(object sender, EventArgs e)
{
CookieContainer cookieJar = new CookieContainer();
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.4shared.com/web/login/validate");
req.Method = "POST";
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
req.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7");
req.KeepAlive = true;
req.Headers.Add("Keep-Alive: 300");
req.AllowAutoRedirect = false;
req.ContentType = "application/x-www-form-urlencoded";
req.CookieContainer = cookieJar;
String Username = "user%40email.com";
String PassWord = "password";
StreamWriter sw = new StreamWriter(req.GetRequestStream());
sw.Write("login=" + Username + "&password=" + PassWord);
sw.Close();
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1255));
string tmp = reader.ReadToEnd();
HttpWebRequest req2 = (HttpWebRequest)HttpWebRequest.Create("http://www.4shared.com/account/home.jsp");
req2.Method = "GET";
req2.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
req2.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7");
req2.KeepAlive = true;
req2.Headers.Add("Keep-Alive: 300");
req2.CookieContainer = cookieJar;
req2.ContentType = "text/html";
HttpWebResponse response2 = (HttpWebResponse)req2.GetResponse();
StreamReader reader2 = new StreamReader(response2.GetResponseStream(), Encoding.GetEncoding(1255));
string tmp2 = reader2.ReadToEnd();
response2.Close();
Panel2.Text = tmp2;