I am using WinHTTP.WinHTTPRequest to send a request to a server.
I am having trouble with an error "OLE IDispatch exception code 0 from WinHTTP.WinHTTPRequest: a connection to the server could not be established.
I have ensured that my headers are all correct. To check this I added the same headers with an add-on in Chrome browser and sent the request. This worked.
The error occurs at the .send() method.
Is there any flags or setting I need to make before the send method?
I am having trouble with an error "OLE IDispatch exception code 0 from WinHTTP.WinHTTPRequest: a connection to the server could not be established.
I have ensured that my headers are all correct. To check this I added the same headers with an add-on in Chrome browser and sent the request. This worked.
The error occurs at the .send() method.
Is there any flags or setting I need to make before the send method?
Code:
SELECT cTable
lcURL = ALLTRIM(companyURL) && the URL that forms part of every request for data
lcAccessToken= 'Bearer ' + ALLTRIM(Access_token)
lcUserPass = STRCONV(ALLTRIM(Username) + ':' + ALLTRIM(Password),13)
lcApi=ALLTRIM(apikey)
LOCAL ServerRequest AS WinHttp.WinHttpRequest
oServerRequest = CREATEOBJECT("WinHttp.WinHttpRequest.5.1")
oServerRequest.Open("GET",lcURL, .f.)
oServerRequest.SetRequestHeader('Authorization',lcAccessToken)
oServerRequest.SetRequestHeader('x-myobapi-cftoken',lcUserPass)
oServerRequest.SetRequestHeader('x-myobapi-key',lcApi)
oServerRequest.SetRequestHeader('x-myobapi-version','v2')
oServerRequest.SetRequestHeader('Content-Type','application/json')
oServerRequest.SetRequestHeader('Accept-Encoding','gzip,deflate')
oServerRequest.Send()
lcResponseText = "" + oServerRequest.ResponseText