如何将HttpCookie身份验证传递给HttpWebRequest [英] How do I pass HttpCookie authentication to HttpWebRequest
本文介绍了如何将HttpCookie身份验证传递给HttpWebRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试以html格式下载页面时,页面不会保存会话并将您带回登录页面。如何将HttpCookie传递给HttpWebRequest进行验证?
或者它可以与会话一起使用吗?代码适用于没有登录会话的页面。
我已经在登录时创建了加密的cookie。
我只需要知道如何读取cookie,以便HttpWebRequest知道用户已经过验证。
When I try to download the page as html the pages does not hold the session and takes you back to the login page. How do I pass the HttpCookie to the HttpWebRequest for validation?
Or can it work with a session? The code works on a page that does not have a login session.
I already created the the encrypted cookie on login.
I just need to know how to read the cookie so HttpWebRequest knows the user is validated.
HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(this.Page.Request.Url.ToString());
myWebRequest.Method = "GET";
myWebRequest.AllowAutoRedirect = false;
// make request for web page
HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();
StreamReader myWebSource = new StreamReader(myWebResponse.GetResponseStream());
string myPageSource = string.Empty;
myPageSource = myWebSource.ReadToEnd();
myWebResponse.Close();
推荐答案
这篇关于如何将HttpCookie身份验证传递给HttpWebRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文