cancel
Showing results for 
Search instead for 
Did you mean: 

retrieving header values of web client function

Baron
Participant
1,166

I am consuming external webservices from my SQL-Anywhere 17 and I am interested in the HTTPSTATUS of the response more than the body itself, so I want just to check if the call to the webservice has succeeded (i.e. whether I got 200 OK as HTTP Status)!

I tried to write something like this, but I get always an empty string in my @ResponseStatus variable!

create or replace function UpdateAPI(EndPoint varchar(200), UserName varchar(200), PWD varchar(200), PayLoad long varchar)

returns long varchar

url 'http://!UserName:!PWD@!EndPoint'

type 'http:put:application/json';


begin

declare @ResponseBody long varchar;

declare @ResponseStatus long varchar;

set @ResponseBody = WC_UpdateAPI(@Endpoint, @username, @pwd, @PayLoad);

set @ResponseStatus = HTTP_RESPONSE_HEADER('@HttpStatus');

select @ResponseBody, @ResponseStatus;

end;

On the other side, I can see this HTTP Response in the WebClientLogFile (as HTTP/1.0 200 OK).

Could please somebody tell me Where I am doing mistake?

Accepted Solutions (1)

Accepted Solutions (1)

VolkerBarth
Contributor

You need to use a web client procedure (instead of a web client function) to have access to the full response, web client functions just return the response's body.

See here and here for details.

Baron
Participant
0 Kudos

Thank you very much. It has worked even with the parameter substitution

Baron
Participant
0 Kudos

One more question, how can I then get both "body" and "Status" using one single call?

In the mentioned example how can I merge those both calls in one call:

SELECT "value" FROM SAPWebPage() WITH (Attribute LONG VARCHAR, Value LONG VARCHAR, Instance INT) WHERE Attribute = 'Status';

SELECT "value" FROM SAPWebPage() WITH (Attribute LONG VARCHAR, Value LONG VARCHAR, Instance INT) WHERE Attribute = 'body';

VolkerBarth
Contributor

You mean, get those values

  1. as two columns within one row or
  2. within two rows?

For the 1. you can use a PIVOT clause:

SELECT "'Status'" AS STATUS, "'Body'" AS Body
FROM
   (SELECT "attribute", "value"
    FROM SAPWebPage() 
       WITH (Attribute LONG VARCHAR, Value LONG VARCHAR, Instance INT)) ST
   PIVOT (min("value") FOR "attribute" in ('Status', 'Body')) PT

For the second, you would obviously just do something like:

SELECT "attribute", "value"
FROM SAPWebPage() 
   WITH (Attribute LONG VARCHAR, Value LONG VARCHAR, Instance INT)
WHERE "attribute" in ('Status', 'Body')
Baron
Participant
0 Kudos

Thanks, I was meaning the first one (with this MAGIC Clause PIVOT)

¯_(ツ)_/¯

Answers (0)