I have encountered a problem when I try to visit a web page (like
http://www.xxx.org....?arg1=x&arg2=x&....) using HttpWebRequest and
HttpWebResponse and related methods .NET provides.The code is like this:
....
HttpWebRequest r = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse rp = r.GetResponse();
....
However,I've got the error page that is redirected to by the page I
request.And the response page says that "you have no permission to visit this
page.Please login first!".So,I find the login page (like
http://www.xxx.org/login.asp") and get the form fields such as username and
password.Then,I request the login page using method POST like :
....
string postData = "username=myusername&password=mypassword&...";
byte[] data = Encoding.ASCII.GetBytes(postData);
HttpWebRequest rlogin = (HttpWebRequest)WebRequest.Create(login_url);
rlogin.Method = "POST";
rlogin.ContentType = "application/x-form-un....";
Stream loginStream = rlogin.GetRequestStream();
rlogin.ContentLength = data.Length;
loginStream.Write(data,0,data.Length);
HttpWebResponse rplogin = rlogin.GetResponse();
....
The response page tells me that login successfully.Then,I try to request the
original page again,however,the permission error occurs once again.
How can I solve such problem?
I noticed that the web site has stored cookie information on my
computer,because when I directly request the web page in Internet Exporer,I
can get the correct web page.Thus,How to access the cookie and associate it
to the HttpWebRequest in my application?
Thanks.