1. Andreas Bastian
  2. PowerBuilder
  3. Wednesday, 5 October 2022 08:38 AM UTC

Hello friends,

I'm trying to address a WEB service with an httpclient-object and the get-method, but I always get the status message 401.

I'm using the following code:

HttpClient lnv_HttpClient
lnv_HttpClient = Create HttpClient
string ls_uer, ls_token, ls_string
integer li_status, li_req
 
ls_user = 'user_x'
ls_token = 'long_given_token_x'

lnv_HttpClient.SetRequestHeader("Host", "pp.xx.qwertz.com")

li_req = lnv_HttpClient.SetRequestHeader('qwertz-ConsumerId', ls_user)

li_req = lnv_HttpClient.SetRequestHeader('qwertz-ConsumerToken', ls_token)

li_req = lnv_HttpClient.SendRequest('GET', 'https://pp.xx.qwertz.com/pp/employeeGet')

if li_req = 1 then
    li_status = lnv_HttpClient.GetResponseStatusCode()

    if li_status = 200 then
         lnv_HttpClient.GetResponseBody(ls_string)
    end if

end if

the same procedure from the same Client-PC works fine when i'am using the extern API-Tool "Postman"

So, what i'am doing wrong?

greetings

Andreas

 

Andreas Bastian Accepted Answer Pending Moderation
  1. Monday, 17 October 2022 10:59 AM UTC
  2. PowerBuilder
  3. # 1

Hello together,

the probelm was:

ls_user = 'user_x'
ls_token = 'long_given_token_x'

the string "long_given_x" contained a spezial character ~

this ~ did not appear in the var: ls_token

if you assign a text to a string var in Power Script, you must replace ~ with ~~

Andreas

 

Comment
  1. Armeen Mazda @Appeon
  2. Monday, 17 October 2022 16:13 PM UTC
Thanks for sharing the solution!
  1. Helpful
There are no comments made yet.
Marco Meoni Accepted Answer Pending Moderation
  1. Wednesday, 5 October 2022 21:07 PM UTC
  2. PowerBuilder
  3. # 2

Hi Andreas,

are you sure the headers you set are same as in PostMan?

As you probably know, 401 means the request lacks valid auth credentials for the requested resource.

If request is ok from Postman, please verify there is no missing header and they are all spelled correctly.

 

Addition check, I'd try to export to C# the Postman request (it's a handy built-in feature) and run it from SnapDevelop.

Best,

.m

Comment
  1. Andreas Bastian
  2. Friday, 7 October 2022 14:23 PM UTC




Hi, thanks for responding,



with c# it works fine with the given haeder - credentials.



with PB 2022 it is still not working an and i have no idea why.



greeting



Andreas

  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.