1. Rick Rockett
  2. PowerBuilder
  3. Wednesday, 6 June 2018 17:30 PM UTC

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.  

Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 6 June 2018 18:20 PM UTC
  2. PowerBuilder
  3. # 1

Hi Rick;

  If you are using a DataWindow for the target result set ... remember that the returned values myst be a 2D result set that utilizes standard DWO data types. Otherwise, the Retrieve() would fail.

Regards ... Chris

Comment
  1. Rick Rockett
  2. Wednesday, 6 June 2018 19:37 PM UTC
I am able to connect to the web service using Soap UI with ease, and I get the following properties of it.



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

  1. Helpful
  1. Rick Rockett
  2. Wednesday, 6 June 2018 20:47 PM UTC
My new code is still not working.  I build the JSON first.



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"



}

  1. Helpful
  1. Govinda Lopez @Appeon
  2. Monday, 11 June 2018 22:58 PM UTC
Hi Rick,



 



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,



 

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.