ASP XMLHTTP组件 GET或POST请求 小偷采集方法anhttp()

此版本不支持User-Agent,可自己在函数内添加。

'HTTP请求方法
' @param   url      请求的URL地址
' @param   data     请求的参数,如client_id=11118888&state=test&...,各个参数请进行URL编码
' @param   method   发送请求的方式,取GET或POST
Function anhttp(url,data,method)
  Set XmlObj = Server.CreateObject("Microsoft.XMLHTTP")
  if method = "POST" then
    XmlObj.open "POST",url,false
  else
    XmlObj.open "GET",url&"?"&data,false
  end if
  XmlObj.setrequestheader "Connection","Keep-Alive"
  XmlObj.setrequestheader "Cache-Control","no-cache"
  if method = "POST" then
    XmlObj.setrequestheader "Content-Length",len(data)
    XmlObj.setrequestheader "Content-Type", "application/x-www-form-urlencoded"
    XmlObj.send(data)
  else
    XmlObj.setrequestheader "Content-Type", "text/html; charset=utf-8"
    XmlObj.send
  end if
  anhttp = XmlObj.responseText
  Set XmlObj = nothing
End Function

 

 

 

 

posted @ 2012-12-04 10:11  Al-one  阅读(425)  评论(0编辑  收藏  举报