asp发送http请求,获取一个url的内容

response.Write("http://"&Request.ServerVariables("HTTP_HOST")&"/jfclear"&Request.ServerVariables("REQUEST_URI"))

Response.Write(GetHttpPage("http://www.baidu.com/","UTF-8"))


Function GetHttpPage(url, charset) 
    Dim http 
    Set http = Server.createobject("Msxml2.ServerXMLHTTP")
    http.Open "GET", url, false
    http.Send() 
    If http.readystate<>4 Then
        Exit Function 
    End If 
    GetHttpPage = BytesToStr(http.ResponseBody, charset)
    Set http = Nothing
End function


Function BytesToStr(body, charset)
    Dim objStream
    Set objStream = Server.CreateObject("Adodb.Stream")
    objStream.Type = 1
    objStream.Mode = 3
    objStream.Open
    objStream.Write body
    objStream.Position = 0
    objStream.Type = 2
    objStream.Charset = charset
    BytesToStr = objStream.ReadText 
    objStream.Close
    Set objStream = Nothing
End Function

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。