I'm trying to make an Excel macro that can make a GET request to a Plumber API that is hosted on RConnect. I have developed the Plumber API, it works as intended. During testing, I ran it on my local machine, so it was running on 127.0.0.1:xxxx, and pasting this as the URL to be accessed in the VBA code worked fine. However, now that I've published the API to RConnect, using the URL for the API from RConnect no longer works from Excel, it just gives an error. Even when I click the URL while it's just typed into a blank cell in Excel, it gives me an error. But when I paste this exact same URL into Chrome, the response text that I expect is there, and it works fine.
The URL request code I was using prior to publishing to RConnect is
Dim objHTTP As Object
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
objHTTP.Open "GET", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHTTP.Send ("keyword=php")
My thinking is that it is some kind of issue with the CreateObject
line, but I'm not sure. I don't have experience with web development, so much of this is foreign to me. Any help or input would be greatly appreciated. Thanks.