VB 通过XMLhttp 进行POST提交数据,Get数据采集,网页下载

Function HttpGet(Url As String) As String
     '函数返回值是获得的返回信息(HTML)
     '第一个参数是要发送的Url地址
     Dim XmlHttp As Object
     Set XmlHttp = CreateObject("Msxml2.XMLHTTP")
     If Not IsObject(XmlHttp) Then
         Set XmlHttp = CreateObject("Microsoft.XMLHTTP")
         If Not IsObject(XmlHttp) Then Exit Function
     End If
     XmlHttp.Open "GET", Url, False
     XmlHttp.Send
'     Do While XmlHttp.readyState <> 4
'         DoEvents
'     Loop
     '如果把下面一行(以及后面的End IF)的注释去除,即设置为仅当返回码是200时才返回页面内容
     'If XmlHttp.Status = 200 Then
         HttpGet = XmlHttp.responseText
     'End If
End Function


Function HttpPost(Url As String, PostMsg As String) As String
     '自己写的发送Post的函数
     '函数返回值是获得的返回信息(HTML)
     '第一个参数是要发送的Url地址
     '第二个参数是要发送的消息(键值对应,不必编码)
     Dim XmlHttp As Object
     Set XmlHttp = CreateObject("Msxml2.XMLHTTP")
     If Not IsObject(XmlHttp) Then
         Set XmlHttp = CreateObject("Microsoft.XMLHTTP")
         If Not IsObject(XmlHttp) Then Exit Function
     End If
     XmlHttp.Open "POST", Url, False
     XmlHttp.setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded; charset=UTF-8"
     XmlHttp.Send PostMsg
 
     '如果把下面一行(以及后面的End IF)的注释去除,即设置为仅当返回码是200时才返回页面内容
     'If XmlHttp.Status = 200 Then
         HttpPost = XmlHttp.responseText
     'End If
End Function

你可能感兴趣的:(ui,前端,javascript)