从登录后的页面获取 HTML
这个问题是我的上一个问题关于从 ASPX 页面获取 HTML 的后续问题。 我决定尝试使用 webclient 对象,但问题是我获取了登录页面的 HTML,因为需要登录。 我尝试使用 webclient 对象“登录”:
WebClient ww = new WebClient();
ww.DownloadString("Login.aspx?UserName=&Password=");
string html = ww.DownloadString("Internal.aspx");
但我仍然始终得到登录页面。 我知道用户名信息没有存储在 cookie 中。 我一定是做错了什么或者遗漏了重要的部分。 有谁知道它可能是什么?
This question is a follow up to my previous question about getting the HTML from an ASPX page. I decided to try using the webclient object, but the problem is that I get the login page's HTML because login is required. I tried "logging in" using the webclient object:
WebClient ww = new WebClient();
ww.DownloadString("Login.aspx?UserName=&Password=");
string html = ww.DownloadString("Internal.aspx");
But I still get the login page all the time. I know that the username info is not stored in a cookie. I must be doing something wrong or leaving out an important part. Does anyone know what it could be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
使用 Fiddler 查看通过浏览器手动执行操作时发生的 HTTP 请求和响应。
Use Fiddler to see the HTTP requests and responses that happen when you do it manually through the browser.
@Fire Lancer:我在测试期间问了自己同样的问题,所以我检查了,它确实可以在浏览器中工作。
@Fire Lancer: I asked myself that same question during my tests, so I checked, and it does work from a browser.
由于我试图获取的 aspx 页面位于我自己的项目中,因此我可以使用 Server.Execute 方法。 更多详细信息请参阅我对原始问题的回答
As the aspx page I was trying to get was in my own projct, I could use the Server.Execute method. More details in my answer to my original question
将 Firefox 与 LiveHttpHeaders 插件结合使用。
这将允许您通过实际的浏览器登录并准确查看发送到服务器的内容。 我的第一个问题是验证它是否不需要表单中的 POST。 您正在加载的示例 URL 通过查询字符串 GET 发送信息。
Use Firefox with the LiveHttpHeaders plugin.
This will allow you to login via an actual browser and see EXACTLY what is being sent to the server. My first question would be to verify that it isn't expecting a POST from the form. The example URL you are loading is sending the info via a querystring GET.
在浏览器中使用“Login.aspx?UserName=&Password=”打开页面是否正常工作?
某些页面可能不允许使用 url 中提供的数据进行登录,并且必须在页面的登录表单中输入该数据,然后提交。
Well does opening the page in a brower with "Login.aspx?UserName=&Password=" normaly work?
Some pages may not allow login using data provided in the url, and that it must be entered in the login form on the page and then submitted.
只需将有效的登录参数传递给给定的 URI。 应该可以帮助你。
如果您没有登录信息,则不应尝试规避它。
Just pass valid login parameters to a given URI. Should help you out.
If you don't have login information you shouldn't be trying to circumvent it.
尝试设置 WebClient 对象的凭据属性
Try setting the credentials property of the WebClient object
我能想到的唯一另一个原因是网页故意阻止其登录。如果您有权访问代码,请查看用于查看的登录系统,看看是否有任何旨在阻止此类登录的内容。
The only other reason I can think of then is that the web page is intentionally blocking it from loggin in. If you have access to the code, take a look at the loggin system used to see if theres anything designed to block such logins.