Dim xmlHttp As Object
Private Function aaa(url As String)
Set xmlHttp = CreateObject("Microsoft.XMLHTTP")
xmlHttp.Open "GET", url, True
xmlHttp.send (Null)
While xmlHttp.ReadyState <> 4
DoEvents
Wend
aaa = xmlHttp.responseText
End Function
Sub sheep()
MsgBox aaa("http://www.baidu.com")
End Sub
'==============================一下是POST数据实例====================
Sub test2()
Dim xmlhttp
Set xmlhttp = CreateObject("msxml2.xmlhttp")
With xmlhttp
.Open "POST", "http://127.0.0.1:8012/json.php?mode=9", False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.send "mode=9"
MsgBox .responseText '显示POST之后网页返回的结果
End With
Set xmlhttp = Nothing
End Sub
本文提供了一个使用VBA进行HTTP GET和POST请求的示例。GET请求通过创建Microsoft.XMLHTTP对象来获取网页内容,而POST请求则展示了如何设置请求头并发送数据到指定服务器。
1378

被折叠的 条评论
为什么被折叠?



