在 CURL 中,我可以使用这一行
curl --data 'DataToBeSent' https://example.com/resource.cgi
我正在努力将此类行转换为在 VBA 中使用,这是我到目前为止的尝试
Sub POST_Method_Example()
Dim myMessage As String
myMessage = "DataToBeSent"
With CreateObject("MSXML2.ServerXMLHTTP")
.Open "POST", "https://example.com/resource.cgi"
.setRequestHeader "Content-Type", "multipart/form-data; boundary==------------------------d74496d66958873e"
.send sData(myMessage)
Debug.Print .ResponseText
End With
End Sub
但这会在 json 响应中引发错误。我怎样才能使它适用于 VBA?
我可以通过分配 url 让它在邮递员上工作,在“正文”选项卡中我选择“表单数据”并分配键:文本和值:DataToBeSent
这将返回成功的响应。
See 多部分/表单数据 https://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean何时使用。
Sub POST_Method_Example()
With CreateObject("MSXML2.ServerXMLHTTP")
.Open "POST", "https://example.com/resource.cgi"
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.send "text=Data to be sent"
Debug.Print .ResponseText
End With
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)