Oracle HTTP请求接收! .

create or replace procedure p_sendsms(l_type         in varchar2,
                                      l_phoneNo      in varchar2,
                                      l_content      in varchar2,
                                      l_err_code       out integer,
                                      l_ora_code       out integer) is
  l_respond varchar2(4000); --响应报文
  http_req  utl_http.req; --请求包头
  http_resp utl_http.resp; --响应包头
BEGIN
http_req := utl_http.begin_request('http:senderServlet?mobiles=' ||
                                     l_phoneNo || '&content=' || l_content ||
                                     '&type=' || l_type,
                                     'POST',
                                     utl_http.HTTP_VERSION_1_1 /* 'HTTP/1.1'*/);
  utl_http.set_header(http_req,
                      'Content-Type',
                      'application/x-www-form-urlencoded;charset=utf-8');
  http_resp := utl_http.get_response(http_req); --提交请求

  if http_resp.status_code = utl_http.HTTP_OK then
    --成功才读取响应消息
    utl_http.read_text(http_resp, l_respond);
    utl_http.end_response(http_resp); --结束请求
    l_respond := substr(l_respond, 1, 4000); ---long 转成 varchar2
    dbms_output.put_line(l_respond); --打印响应消息
    dbms_output.put_line(http_resp.reason_phrase); --打印响应消息
  else
    l_err_code := http_resp.status_code;
    l_ora_code := sqlcode;
    dbms_output.put_line(http_resp.reason_phrase); --打印响应消息
  end if;
exception
  WHEN OTHERS THEN
    l_ora_code := sqlcode;
END;

你可能感兴趣的:(oracle)