vba VBA中的等效cURL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17063550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 15:51:06  来源:igfitidea点击:

Equivalent cURL in VBA?

vbacurlaccess-vba

提问by adam Kearsley

I have an API for my application which allows me to make cURL requests to it. I need to implement this into VBA so my desktop database can fire CURL requests to my web app.

我的应用程序有一个 API,它允许我向它发出 cURL 请求。我需要将其实现到 VBA 中,以便我的桌面数据库可以向我的 Web 应用程序发出 CURL 请求。

curl -i --user [email protected]:password -X PUT -d "test=testing" https://mywebsite.com/api

How can i implement this in Access VBA? Can i use WinHttp.WinHttpRequest.5.1 ? Any examples? Thanks Adam,

如何在 Access VBA 中实现这一点?我可以使用 WinHttp.WinHttpRequest.5.1 吗?有什么例子吗?谢谢亚当,

回答by adam Kearsley

Solved it now guys, works well. For other peoples convenience.

现在解决了伙计们,效果很好。为了其他人的方便。

TargetURL = "https://www.mysite.co.uk/app/api/v1/test"
Set HTTPReq = CreateObject("WinHttp.WinHttpRequest.5.1")
HTTPReq.Option(4) = 13056 '
HTTPReq.Open "PUT", TargetURL, False
HTTPReq.SetCredentials "user", "password", 0
HTTPReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HTTPReq.send ("test[status]=" & Forms!curl!Text0.Value & "&test2[status]=" & Text2.Value)
MsgBox (HTTPReq.responseText)