How to invoke a webservice through pl/sql block for which we know url,username and password.
And how to see the response?
Give some sample code...
Thanks in advance
I have used the following piece of code:
CREATE OR REPLACE FUNCTION READ_DATA_FROM_WS (url IN VARCHAR2,
username IN VARCHAR2,
password IN VARCHAR2)
RETURN CLOB
IS
req UTL_HTTP.req;
resp UTL_HTTP.resp;
DATA VARCHAR2 (2000);
data1 CLOB;
def_timeout PLS_INTEGER;
l_envelope VARCHAR2(32767);
BEGIN
req := utl_http.begin_request(url, 'POST','HTTP/1.0');
UTL_HTTP.set_authentication (req, username, password);
utl_http.set_header(req, 'Content-Type', 'text/xml');
resp := utl_http.get_response(req);
IF (resp.status_code = UTL_HTTP.http_ok)
THEN
UTL_HTTP.set_body_charset (resp, 'UTF-8');
BEGIN
LOOP
UTL_HTTP.read_text (resp, DATA);
data1 := data1 || DATA;
END LOOP;
EXCEPTION
WHEN UTL_HTTP.end_of_body
THEN
UTL_HTTP.end_response (resp);
UTL_HTTP.set_transfer_timeout (def_timeout);
WHEN OTHERS
THEN
NULL;
END;
UTL_HTTP.set_transfer_timeout (def_timeout);
ELSE
UTL_HTTP.end_response (resp);
DBMS_OUTPUT.put_line ('HTTP response status code: ' || resp.status_code);
END IF;
RETURN (data1);
END read_data_from_ws;
/