0

我想HTML从页面获取代码:http: //trendstop.knack.be/nl/detail/446121707/6x-international.aspx 但每次我使用以下方式HTML发出请求时:

  Imports System
  Imports System.IO
  Imports System.Web
  Imports System.Net
  Imports System.IO.IsolatedStorage
  Imports System.Threading
  Imports Microsoft.VisualBasic
  Imports System.Text

  Public Class GetSource
      Function GetHTML(ByVal strPage As String) As String
          Dim strReply As String = "NULL"

    Try
        Dim objHttpRequest As System.Net.HttpWebRequest
        Dim objHttpResponse As System.Net.HttpWebResponse
        objHttpRequest = System.Net.HttpWebRequest.Create(strPage)


        objHttpResponse = objHttpRequest.GetResponse

        Dim objStrmReader As New StreamReader(objHttpResponse.GetResponseStream)

        strReply = objStrmReader.ReadToEnd()

    Catch ex As Exception
        strReply = "ERROR! " + ex.Message.ToString
    End Try

          Return strReply

      End Function


  End Class

我得到了重定向网址http://trendstop.knack.be/nl/detail/446121707/6x-international/activity.aspx的 html

我怎样才能获得原始的html代码url

4

2 回答 2

1

也许您想将 AllowAutoRedirect 属性设置为“false”?

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.allowautoredirect.aspx

于 2013-07-22T09:45:03.230 回答
0

这可能是由于用户代理问题。如果某些值不可用,某些站点会尝试读取您的用户代理并重定向。

您是否尝试过设置用户代理?你还会被重定向吗?

objHttpRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
于 2013-07-22T10:14:46.673 回答