on 2020 Apr 10 3:29 PM
I am consuming an external webservice from within my SQL Anywhere 17 using the following code:
create or replace function F1("JsonLoad" long varchar)
returns long varchar
url 'https://USER:PWD@localhost/index.php/mytest'
CERTIFICATE 'file=C:\\TEMP\\mycer.cer'
type 'http:post:application/json'
create or replace procedure P1("JsonLoad" long varchar)
begin
call F1(JsonLoad);
end;
The question is, how can I feed the USER & PWD from within P1?
OR
How can I change the definition of F1 so that it reads the values of USER & PWD from a table in DB
Request clarification before answering.
You can use parameter substitution
Example (note the !user and !pwd in the url clause):
create or replace function F1( "user" long varchar, "pwd" long varchar, "JsonLoad" long varchar ) returns long varchar url 'https://!user:!pwd@localhost/index.php/mytest' CERTIFICATE 'file=C:\\TEMP\\mycer.cer' type 'http:post:application/json' create or replace procedure P1("JsonLoad" long varchar) begin call F1( 'myuser', 'mypassword', JsonLoad ); end;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just to add: Like Mark has shown above and answered here, web client functions (and also web client procedures) can be parameterized with the "!param" syntax - but the work to calculate or query values for these parameters must be done outside the web client functions.
Web client functions simply build a request from their input values, send it to the according web server, wait for the response and fetch and return it in the desired way. And that's all (although technically, that's certainly pretty much work...).
So in most cases you will need wrappers (usually "normal" functions/procedures like P1 in your sample) to calculate parameter values for the web client functions (say, by querying database contents and the like), then calling the web client function with these parameters, and then probably work on the web client function's return value to pick up the relevant information like error states, particular fields and the like. I have never used a web client function without having to wrap its call with one or more "outer" functions and produres.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
29 | |
9 | |
8 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.