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

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐