Greetings,
I am having difficulty getting my RESTful webservice to authenticate. I know that the webservice is up because when I use the following code, I get a Return code 401 - Unauthorized.
rest.Retrieve(dw_rest_poc, ls_url)
ll_code = rest.GetResponseStatusCode()
ls_code_text = rest.GetResponseStatusText()
I am now trying to authenticate and from everything I read it seems to me I am doing it correctly, what am I missing?
ls_header = ls_login + ":" + ls_password
I then convert that ls_header string to Base64. Then I do the SetRequestHeader
rest.Setrequestheader("Authorization", "Basic " + ls_encoded)
Now when I do the retrieve, I only get a -1 return code.
POST https://XXXXXXXX/ws/rest/rEcho HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/json
Content-Length: 54
Host: cledli01:9090
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Authorization: Basic XXXXXXX
ls_json = '{"Parm1":"First", "Parm2":"Second", "Parm3":"Third"}'
Next I add the Authorization
ll_rc = rest.Setrequestheader("Authorization", "Basic " + ls_encoded)
My datawindow has 4 fields, all string(100), external datawindow
ll_rows = rest.Retrieve(dw_rest_poc, ls_url, ls_json)
This is the expected Output which I get with SoapUI
{
"OutParm1": "First",
"OutParm2": "20180604 145934.262",
"OutParm3": "Second",
"OutParm4": "Third"
}
Have you tried using the double quotes? For example:
ls_authentication = '{ "username" : "' + ls_username + '", "password" : "' + ls_pass + '" }'
That sometimes is a problem for some web services not accepting the JSON for incorrect formatting of the strings. This tool might help you checking the format of your JSON.
Regards,