Skip to content

Instantly share code, notes, and snippets.

@Kelvin-Lei
Created November 16, 2015 03:43
Show Gist options
  • Select an option

  • Save Kelvin-Lei/f673d52d2306b08b6f51 to your computer and use it in GitHub Desktop.

Select an option

Save Kelvin-Lei/f673d52d2306b08b6f51 to your computer and use it in GitHub Desktop.
ORACLE DB发送HTTP请求
/*==================================
ORACLE DB SEND GET HTTP REQUEST
====================================*/
DECLARE
l_req utl_http.req;
l_resp utl_http.resp;
l_url VARCHAR2(200);
l_resp_txt VARCHAR2(30000);
BEGIN
l_url := 'http://127.0.0.1/IK2WorkflowService/Test/?id=102';
l_req := utl_http.begin_request(l_url, 'GET', utl_http.HTTP_VERSION_1_1);
utl_http.set_header(l_req, 'Content-Type', 'text/html; charset=utf-8');
l_resp := utl_http.get_response(l_req);
utl_http.read_text(l_resp, l_resp_txt);
dbms_output.put_line(l_resp_txt);
utl_http.end_response(l_resp);
EXCEPTION
WHEN utl_http.end_of_body THEN
utl_http.end_response(l_resp);
END;
/*==================================
ORACLE DB SEND POST HTTP REQUEST
====================================*/
DECLARE
l_req utl_http.req;
l_resp utl_http.resp;
l_url VARCHAR2(200);
l_clob CLOB;
l_req_blob BLOB;
l_resp_txt VARCHAR2(32767);
BEGIN
l_url := 'http://127.0.0.1/IK2WorkflowService/TestJson';
l_req := utl_http.begin_request(l_url, 'POST', utl_http.HTTP_VERSION_1_1);
utl_http.set_header(l_req, 'Content-Type', 'text/json; charset=UTF-8');
utl_http.set_header(l_req, 'Keep-Alive', ' timeout=1');
dbms_lob.createtemporary(lob_loc => l_clob, cache => TRUE);
l_clob := '{"TestId":1,"TestDesc":"Just For Testing(测试)"}';--POST参数的内容(Json格式)
dbms_lob.createtemporary(lob_loc => l_req_blob, cache => TRUE);
cux_CE_lob_pub.clob2blob(p_clob => l_clob,
x_blob => l_req_blob,
p_cset_f => 'UTF8',
p_cset_t => 'UTF8');
utl_http.set_header(l_req, 'Content-Length', dbms_lob.getlength(l_req_blob));
utl_http.write_raw(l_req, l_req_blob);
l_resp := utl_http.get_response(l_req);
utl_http.read_text(l_resp, l_resp_txt);
dbms_output.put_line(l_resp_txt);
utl_http.end_response(l_resp);
EXCEPTION
WHEN utl_http.end_of_body THEN
utl_http.end_response(l_resp);
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment