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?

asked 05 May, 04:30

Baron's gravatar image

Baron
1.3k4973114
accept rate: 33%

edited 05 May, 04:30


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.

permanent link

answered 05 May, 04:46

Volker%20Barth's gravatar image

Volker Barth
36.9k343505765
accept rate: 34%

edited 05 May, 04:48

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

(05 May, 07:42) Baron
Replies hidden

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';

(05 May, 07:56) Baron
1

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')
(05 May, 08:07) Volker Barth

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

¯_(ツ)_/¯

(05 May, 08:36) Baron
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×43

question asked: 05 May, 04:30

question was seen: 158 times

last updated: 05 May, 08:39