17

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.

curl -i --user admin@admin.com: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,

Erik A
  • 31,639
  • 12
  • 42
  • 67
adam Kearsley
  • 951
  • 2
  • 13
  • 23

1 Answers1

29

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)
adam Kearsley
  • 951
  • 2
  • 13
  • 23
  • 3
    What is the significance of Option(4)? The [WinHttpRequest documentation](http://msdn.microsoft.com/en-us/library/windows/desktop/aa384106(v=vs.85).aspx) doesn't specify. – StockB Oct 16 '13 at 14:51
  • 2
    I know it is 3 years ago, but I also wondered what this Option(4) is there fore and I found some useful information under this link http://johankanngard.net/2005/11/11/winhttprequest-com-object-options-constants/ – rodedo Sep 27 '16 at 08:38
  • 3
    According to the [WHR Option docs](https://learn.microsoft.com/en-us/windows/desktop/winhttp/winhttprequestoption), the 4 is the enumeration value "WinHttpRequestOption_SslErrorIgnoreFlags". If you convert the 13056 to hex, you get 0x3300, which if you look further down to the SslErrorIgnoreFlags description, you can see that this ignores all the errors. – livefree75 Dec 19 '18 at 14:54
  • Thank u a lot. I used a Get method, so I didn't use parameters, only url, but it worked just fine. Thank you again – Juan Joya Jun 12 '20 at 04:26