vb.NET WebRequest读取aspx页面到字符串,访问被拒绝?
我正在尝试在 VS2008 中创建一个可执行文件,它将使用 vb.NET 函数将网页源代码读取到字符串变量中。问题是该页面不是 *.html,而是 *.aspx。
我需要一种方法来执行 aspx 并将显示的 html 转换为字符串。
我想阅读的页面是此类型的任何页面:http://www.realtor。 ca/PropertyDetails.aspx?PropertyID=9620716
我尝试了以下代码,该代码适用于 html 页面,但当我传入上面的 aspx 页面时,会生成页面标题“访问被拒绝”的错误源代码。
Dim myReq As WebRequest = WebRequest.Create(url)
Dim myWebResponse As WebResponse = myReq.GetResponse()
Dim dataStream As Stream = myWebResponse.GetResponseStream()
Dim reader As New StreamReader(dataStream, System.Text.Encoding.UTF8)
Dim responseFromServer As String = reader.ReadToEnd()
有什么建议或想法吗?
I'm trying to make an executable in VS2008 that will read a webpage source code using a vb.NET function into a string variable. The problem is that the page is not *.html but rather *.aspx.
I need a way to execute the aspx and get the displayed html into a string.
The page I want to read is any page of this type: http://www.realtor.ca/PropertyDetails.aspx?PropertyID=9620716
I have tried the following code, which works properly for html pages, but generates the wrong source code with "access denied" for the page title when I pass in the above aspx page.
Dim myReq As WebRequest = WebRequest.Create(url)
Dim myWebResponse As WebResponse = myReq.GetResponse()
Dim dataStream As Stream = myWebResponse.GetResponseStream()
Dim reader As New StreamReader(dataStream, System.Text.Encoding.UTF8)
Dim responseFromServer As String = reader.ReadToEnd()
Any suggestions or ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从命令行运行 wget 时我得到了同样的结果:
我猜服务器依赖于在传递响应之前在浏览器中设置的某些内容,例如 cookie。您可能想尝试使用 WebBrowser 控件(你不必让它可见)通过以下方式(这有效):
I get the same thing while running wget from the command line:
I guess the server is relying on that something is set in the browser before the response is delivered, e.g. a cookie. You might want to try using a WebBrowser control (you don't have to have it visible) in the following way (this works):