Dim xmlHtppDownPage As XMLHTTP
Public Function DownPage(ByVal strUrl As String) As String
DownPage = ""
On Error GoTo error1:
If xmlHtppDownPage Is Nothing Then
Set xmlHtppDownPage = New XMLHTTP
End If
xmlHtppDownPage.open "GET", strUrl, False
xmlHtppDownPage.send
If xmlHtppDownPage.Status <> 200 Then
Exit Function
End If
DownPage = BytesToBstr(xmlHtppDownPage.responseBody, "GB2312")
Exit Function
error1:
End Function
error1:
End Function
Function BytesToBstr(ByVal body As String, ByVal strEncode As String) As String
BytesToBstr = ""
On Error GoTo error1:
Dim objstream As ADODB.Stream
Set objstream = New ADODB.Stream
objstream.Type = adTypeText
objstream.Mode = adModeReadWrite
objstream.open
objstream.WriteText body
objstream.Position = 0
objstream.Type = adTypeText
objstream.Charset = strEncode '转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP组件调用有中文字符的网页得到的将是乱码
BytesToBstr = objstream.ReadText
objstream.Close
Set objstream = Nothing
Exit Function
error1:
End Function
BytesToBstr = ""
On Error GoTo error1:
Dim objstream As ADODB.Stream
Set objstream = New ADODB.Stream
objstream.Type = adTypeText
objstream.Mode = adModeReadWrite
objstream.open
objstream.WriteText body
objstream.Position = 0
objstream.Type = adTypeText
objstream.Charset = strEncode '转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP组件调用有中文字符的网页得到的将是乱码
BytesToBstr = objstream.ReadText
objstream.Close
Set objstream = Nothing
Exit Function
error1:
End Function