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.Cre ate(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=myuse rname&password= mypassword&..." ;
byte[] data = Encoding.ASCII. GetBytes(postDa ta);
HttpWebRequest rlogin = (HttpWebRequest )WebRequest.Cre ate(login_url);
rlogin.Method = "POST";
rlogin.ContentT ype = "applicatio n/x-form-un....";
Stream loginStream = rlogin.GetReque stStream();
rlogin.ContentL ength = data.Length;
loginStream.Wri te(data,0,data. Length);
HttpWebResponse rplogin = rlogin.GetRespo nse();
....
The response page tells me that login successfully.Th en,I try to request the
original page again,however,t he permission error occurs once again.
How can I solve such problem?
I noticed that the web site has stored cookie information on my
computer,becaus e 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.