Send a request with POST parameters via ORACLE's UTL_HTTP toolkit

DECLARE
  req       utl_http.req;
  resp      utl_http.resp;
  l_clob    CLOB;
  l_buf_raw RAW(10000);
  amount    NUMBER := 9000;
  VALUE     VARCHAR2(1000);
  l_process VARCHAR2(20);
  l_req_blob    BLOB;
  l_buf_len_std NUMBER := 900;
  l_buf_len_cur NUMBER;
  l_bod_len     NUMBER;
BEGIN
  req := utl_http.begin_request('http://159.77.226.31/logincheck.asp', 'POST');
  utl_http.set_header(req, 'Content-Type','application/x-www-form-urlencoded'); --This parameter represents that the request contains POST data
  utl_http.set_header(req, 'Keep-Alive', 'timeout=1');--This parameter represents timeout
  dbms_lob.createtemporary(lob_loc => l_clob, cache => TRUE);
  l_clob := 'muser=32323&&passwd=232323&&x=33&&y=17';--The content of the POST parameter, the format is: variable=value&variable=value
  dbms_lob.createtemporary(lob_loc => l_req_blob, cache => TRUE);
  heb_lob_pub.clob2blob(p_clob => l_clob, x_blob => l_req_blob,
                        p_cset_f => 'utf8', p_cset_t => 'utf8');
  utl_http.set_header(req, 'Content-Length', dbms_lob.getlength(l_req_blob));--This parameter represents the length of the POST message I send, which is indispensable
  utl_http.write_raw(req, l_req_blob);
  resp := utl_http.get_response(req);
  LOOP
    utl_http.read_line(resp, VALUE, TRUE);
    dbms_output.put_line(VALUE);
  END LOOP;
  utl_http.end_response(resp);
  utl_http.end_request(req);
EXCEPTION
  WHEN utl_http.end_of_body THEN
    utl_http.end_response(resp);
  WHEN OTHERS THEN
    utl_http.end_response(resp);
    utl_http.end_request(req);
END;

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327061414&siteId=291194637