请看以下代码:
objCookieContainer = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://website.com/login.php?user=xxx&pass=xxx");
request.Method = WebRequestMethods.Http.Get;
request.Timeout = 15000;
request.Proxy = null;
request.CookieContainer = objCookieContainer;
HttpWebRequest newRequest = (HttpWebRequest)WebRequest.Create("http://website.com/page.php?link=url");
newRequest.Method = WebRequestMethods.Http.Get;
newRequest.Timeout = 15000;
newRequest.Proxy = null;
newRequest.CookieContainer = objCookieContainer;
HttpWebResponse response = null;
response = (HttpWebResponse)request.GetResponse();
string readerRequest = new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEnd();
response = (HttpWebResponse)newRequest.GetResponse();
string readerNewRequest = new StreamReader(response.GetResponseStream()).ReadToEnd();
使用 request.GetResponse() 后,cookie 已成功填充数据,并且它具有身份验证代码,并且 readerRequest 也已填充,之后我调用 newRequest.GetResponse() 但 readerNewRequest 为空,我尝试这样做许多事情,但总是相同的结果,我解决这个问题的唯一方法是使用一个 WebBrowser 对象,我在其中传递 url,我能够使用 WebBrowser.DocumentStream 获取内容。
我该如何解决这个问题?