PL/SQL webpage access (get or post), plsql

Source: Internet
Author: User

PL/SQL webpage access (get or post), plsql

When we develop a plsql program, it is inevitable that we sometimes access data from some external websites. At this time, we need to use the utl_http package.

 

Before using the utl_http package, check whether the current user has the permission to access the external network.

 

The following is a summary of the functions. You are welcome to exchange and learn.

Get method:

 1 function http_get(p_url in varchar2) return clob 2     is 3         http_req utl_http.req; 4         http_resp  utl_http.resp; 5         l_raw raw(1024); 6         l_r clob; 7     begin 8         begin 9             http_req:=utl_http.begin_request(p_url,'GET');        10             http_resp := utl_http.get_response(http_req, TRUE);11             loop12                 utl_http.read_raw(http_resp, l_raw,1024);13                 l_r:=l_r||utl_raw.cast_to_varchar2(l_raw);14             end loop;15             utl_http.end_response(http_resp);16             exception17                 when utl_http.end_of_body then18                 utl_http.end_response(http_resp);19         end;20         return l_r;    21     end;

 

Post method:

 1 function  http_post( 2             p_url in varchar2, 3             p_data in varchar2 --a=1&b=2... 4     ) return clob 5     is 6         http_req utl_http.req; 7         http_resp  utl_http.resp; 8         l_raw raw(1024); 9         l_r clob;10     begin11         begin12             http_req:=utl_http.begin_request(p_url,'POST');13             utl_http.set_header(http_req,'Content-Type','application/x-www-form-urlencoded;charset=utf-8');    14             utl_http.set_header(http_req,'Content-Length',length(p_data));    15             utl_http.write_text(http_req,p_data);16             http_resp := utl_http.get_response(http_req, TRUE);17             loop18                 utl_http.read_raw(http_resp, l_raw,1024);19                 l_r:=l_r||utl_raw.cast_to_varchar2(l_raw);20             end loop;21             utl_http.end_response(http_resp);22             exception23                 when utl_http.end_of_body then24                 utl_http.end_response(http_resp);25         end;26         return l_r;    27     end;

The END.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.