Hi All,
Has anyone successfully used restClient.NewSecure (preferred) (also tried sockets, but connection closed error there) to successfully call an https service (specifically azure cognitive services), and if so, could you give me a pointer on what is wrong with my code? Attached is a java routine that works perfectly (DetectLanguage) obviously with a valid key for ACS , but if I try and run what I believe to be the equivalent in the code in Oscript below using RestClient, I get an authentication failure. (Missing access token - but all that should need to be provided is the subscription key that works when called from java using DetectLanguage code.
function CallRestClient()
String hostname = "ottextanalytics.cognitiveservices.azure.com"
Integer port = 443
Integer timeout = 200
Assoc params
List docHeaders={'countryHint','id','text'}
Recarray docArray = RecArray.Create(docHeaders)
Assoc documents
String jsonContent, body
Integer bodyLen = 0
Assoc retVal
//Create connection
RestClient acsClient=RestClient.NewSecure(hostname, port,\
baseURI, timeout)
//Populate parameters
params.("Ocp-Apim-Subscription-Key")="xxxxxxxxxxxxxxxxxx"
params.("Content-Type")="text/json"
//Create JSON content
RecArray.AddRecord(docArray,{'US','1','Hello World'})
jsonContent = web.ToJSON(docArray)
documents.documents = jsonContent
body = web.ToJSON(documents)
bodyLen = Length(body)
// Submit request
retVal = acsClient.Post( params, body, bodyLen)
echo(retVal)
end
Most appreciated if anyone can spot where this is going off the rails
Cheers
Iain