用下面的语句获得网页的源代码,和直接访问获得网页源代码不一样,是咋回事
用下面的语句获得网页的源代码,和直接访问获得网页源代码不一样,是怎么回事?
网页地址:http://finance.sina.com.cn/stock/message/sogusina/sogu600635.htm
Dim url As String = "http://finance.sina.com.cn/stock/message/sogusina/sogu600635.htm " ' 网页地址
Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim httpURL As New System.Uri(url)
httpReq = CType(Net.HttpWebRequest.Create(httpURL), Net.HttpWebRequest)
httpReq.Method = "GET "
httpResp = CType(httpReq.GetResponse(), Net.HttpWebResponse)
httpReq.KeepAlive = False ' 获取或设置一个值,该值指示是否与Internet资源建立持久连接。
Dim reader As IO.StreamReader = New IO.StreamReader(httpResp.GetResponseStream, System.Text.Encoding.GetEncoding( "GB2312 ")) '用GB2312字符
Dim respHTML As String = reader.ReadToEnd() 'respHTML就是网页源代码
RichTextBox1.Text = respHTML
------解决方案--------------------
Try
HttpWebRequest httpWebResponse = (HttpWebRequest)WebRequest.Create( "http://www.baidu.com ");
HttpWebResponse response = (HttpWebResponse)httpWebResponse.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
Console.Write(reader.ReadToEnd());
------解决方案--------------------
Function GetHttpPage(HttpUrl)
If IsNull(HttpUrl)=True or Len(HttpUrl) <18 or HttpUrl= "$False$ " Then
GetHttpPage= "$False$ "
Exit Function
End If
Dim Http
Set Http=server.createobject( "MSXML2.XMLHTTP ")
Http.open "GET ",HttpUrl,False
Http.Send()
If Http.Readystate <> 4 then
Set Http=Nothing
GetHttpPage= "$False$ "
Exit function
End if
GetHTTPPage=bytesToBSTR(Http.responseBody, "GB2312 ")
Set Http=Nothing
If Err.number <> 0 then
Err.Clear
End If
End Function
网页地址:http://finance.sina.com.cn/stock/message/sogusina/sogu600635.htm
Dim url As String = "http://finance.sina.com.cn/stock/message/sogusina/sogu600635.htm " ' 网页地址
Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim httpURL As New System.Uri(url)
httpReq = CType(Net.HttpWebRequest.Create(httpURL), Net.HttpWebRequest)
httpReq.Method = "GET "
httpResp = CType(httpReq.GetResponse(), Net.HttpWebResponse)
httpReq.KeepAlive = False ' 获取或设置一个值,该值指示是否与Internet资源建立持久连接。
Dim reader As IO.StreamReader = New IO.StreamReader(httpResp.GetResponseStream, System.Text.Encoding.GetEncoding( "GB2312 ")) '用GB2312字符
Dim respHTML As String = reader.ReadToEnd() 'respHTML就是网页源代码
RichTextBox1.Text = respHTML
------解决方案--------------------
Try
HttpWebRequest httpWebResponse = (HttpWebRequest)WebRequest.Create( "http://www.baidu.com ");
HttpWebResponse response = (HttpWebResponse)httpWebResponse.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
Console.Write(reader.ReadToEnd());
------解决方案--------------------
Function GetHttpPage(HttpUrl)
If IsNull(HttpUrl)=True or Len(HttpUrl) <18 or HttpUrl= "$False$ " Then
GetHttpPage= "$False$ "
Exit Function
End If
Dim Http
Set Http=server.createobject( "MSXML2.XMLHTTP ")
Http.open "GET ",HttpUrl,False
Http.Send()
If Http.Readystate <> 4 then
Set Http=Nothing
GetHttpPage= "$False$ "
Exit function
End if
GetHTTPPage=bytesToBSTR(Http.responseBody, "GB2312 ")
Set Http=Nothing
If Err.number <> 0 then
Err.Clear
End If
End Function