Sco*_*ott 10 excel post vba http excel-vba winhttprequest
我可以访问API.API将XML帖子作为输入,然后返回带有相关数据的XML响应.
我想要
我在excel中没有编程背景,但对不同的Web脚本语言,HTML,CSS,Javascript等感到满意.
有任何想法吗?
如果您需要将输入xml作为消息正文发送,请执行以下操作.您可能需要添加更多或更改请求标头以使其适用于您.
使用DOMDocument对象可以轻松使用xml文档.
添加项目引用;
例:
Dim xmlInput As String
xmlInput = "<YourXmlRequest></YourXmlPayload>"
Dim oXmlHttp As MSXML2.XMLHTTP60
Set oXmlHttp = New MSXML2.XMLHTTP60
oXmlHttp.Open "POST", serviceURL, False, "UserName", "Password"
oXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oXmlHttp.setRequestHeader "Connection", "Keep-Alive"
oXmlHttp.setRequestHeader "Accept-Language", "en"
oXmlHttp.send xmlInput
Debug.Print oXmlHttp.responseText
Dim oXmlReturn As MSXML2.DOMDocument60
Set oXmlReturn = New MSXML2.DOMDocument60
oXmlReturn.loadXML oXmlHttp.responseText
Run Code Online (Sandbox Code Playgroud)
可以使用此VBA代码处理Excel请求方.
Sub GetStuff()
Dim objXML As Object
Dim strData As String
Dim strResponse As String
strData = "Request"
Set objXML = CreateObject("MSXML2.XMLHTTP")
objXML.Open "POST", "www.example.com/api?" & strData, False
objXML.Send
strResponse = objXML.responsetext
MsgBox strResponse
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
44687 次 |
| 最近记录: |