将 CURL 命令行转换为 VBA
Convert CURL command line to VBA
在 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 让它在邮递员上工作,在 Body 选项卡中我选择 "form-data" 并分配 KEY: text 和 VALUE: DataToBeSent
这 returns 成功响应。
请参阅 multipart/form-data 了解何时使用。
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
在 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 让它在邮递员上工作,在 Body 选项卡中我选择 "form-data" 并分配 KEY: text 和 VALUE: DataToBeSent 这 returns 成功响应。
请参阅 multipart/form-data 了解何时使用。
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