1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
function http_post
(
p_url_in in varchar2
,p_data_in in clob
,p_data_type in varchar2 default 'text/xml'
,p_proxy_in in varchar2 default null
,p_no_proxy_domains_in in varchar2 default null
,p_username_in in varchar2 default null
,p_password_in in varchar2 default null
)
return varchar2 as
l_http_req utl_http.req;
l_http_resp utl_http.resp;
l_my_scheme varchar2(256);
l_my_realm varchar2(256);
l_my_proxy boolean;
data VARCHAR2(1024);
my_context varchar2(4000):=null;
my_db_trc_category varchar(100):='HTTP_TEST';
begin
-- When going through a firewall, pass requests through this host.
-- Specify sites inside the firewall that don't need the proxy host.
-- if (p_proxy_in is not null) and
-- (p_no_proxy_domains_in is not null)
-- then
-- utl_http.set_proxy(p_proxy_in, p_no_proxy_domains_in);
-- end if;
-- Ask UTL_HTTP not to raise an exception for 4xx and 5xx status codes,
-- rather than just returning the text of the error page.
utl_http.set_response_error_check(false);
-- Begin the post request
l_http_req := utl_http.begin_request (p_url_in, 'POST');
--l_http_req := utl_http.begin_request (p_url_in, 'GET');
-- Set the HTTP request headers
utl_http.set_header(l_http_req, 'User-Agent', 'Mozilla/4.0');
utl_http.set_header(l_http_req, 'Transfer-Encoding','chunked');
utl_http.set_header(l_http_req, 'content-type', p_data_type);
utl_http.set_header(l_http_req, 'content-length', length(p_data_in));
-- Specify a user ID and password for pages that require them.
-- if p_username_in is not null then
-- utl_http.set_authentication(
-- l_http_req, p_username_in, p_password_in);
-- end if;
-- Write the data to the body of the HTTP request
utl_http.write_text(l_http_req, p_data_in);
-- Process the request and get the response.
l_http_resp := utl_http.get_response (l_http_req);
utl_http.read_text(l_http_resp, data);
--
-- Look for client-side error and report it.
if (l_http_resp.status_code >= 400) and
(l_http_resp.status_code <= 499)
then
-- Detect whether the page is password protected,
-- and we didn't supply the right authorization.
-- Note the use of utl_http.HTTP_UNAUTHORIZED, a predefined
-- utl_http package global variable
if (l_http_resp.status_code = utl_http.HTTP_UNAUTHORIZED) then
utl_http.get_authentication(
l_http_resp, l_my_scheme, l_my_realm, l_my_proxy);
if (l_my_proxy) then
dbms_output.put_line('Web proxy server is protected.');
dbms_output.put(
'Please supply the required ' ||
l_my_scheme ||
' authentication username/password for realm ' ||
l_my_realm ||
' for the proxy server.');
else
dbms_output.put_line(
'Web page ' || p_url_in || ' is protected.');
dbms_output.put(
'Please supplied the required ' ||
l_my_scheme ||
' authentication username/password for realm ' ||
l_my_realm ||
' for the Web page.');
end if;
else
dbms_output.put_line('Check the URL.');
end if;
utl_http.end_response(l_http_resp);
return(getTagContent(data,'contextId'));
-- Look for server-side error and report it.
elsif (l_http_resp.status_code >= 500) and
(l_http_resp.status_code <= 599)
then
dbms_output.put_line('Check if the Web site is up.');
utl_http.end_response(l_http_resp);
return(getTagContent(data,'contextId'));
end if;
utl_http.end_response (l_http_resp);
return(getTagContent(data,'contextId'));
exception
when others then
dbms_output.put_line (sqlerrm);
raise;
end;-- http_post; |