使用oracle utl_http包需要注意的事項


總結下幾次使用utl_http包遇到的幾個問題

關於utl_http包功能還是很強大的 可以通過他來捕捉網站頁面的內容 或者調用一個url的接口完成某項功能
Eg:
declare
  req  UTL_HTTP.REQ;
  resp UTL_HTTP.RESP;
  v_text varchar2(4000);
begin
  --here you can insert other code even procedure or funciton
  --my codeing is etl monitor
  v_text := etl_monitor; --this is the etl monitor procedure
  if v_text is not null then
  req  := UTL_HTTP.BEGIN_REQUEST('http://192.168.xxx.xxx/pass/web/alertsms.php?data=' ||
                                 v_text);
  resp := UTL_HTTP.GET_RESPONSE(req);
  utl_http.end_response(resp);
  end if;
 
EXCEPTION
  WHEN utl_http.end_of_body THEN
    utl_http.end_response(resp);
end;
使用它來發送短信(告警) 注意這里可以再嵌套其他代碼甚至是過程或函數
今天在調試上述代碼時總是拋出:
declare
*
ERROR at line 1:
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1231
ORA-29263: HTTP protocol error
ORA-06512: at line 11
這個錯誤 測試半天發現是v_text文本內容中含有空格 是調用的接口程序不允許含有空格字符~汗!
 
第二個 關於有時中文亂碼:
declare
  req  UTL_HTTP.REQ;
  resp UTL_HTTP.RESP;
  val  varchar2(32767);
begin
 
  req := UTL_HTTP.BEGIN_REQUEST('xxx');
  utl_http.set_header(req, 'Content-Type', 'text/html; charset=utf-8');--add this
  resp := UTL_HTTP.GET_RESPONSE(req);
  utl_http.read_line(resp, val, true);
  utl_http.end_response(resp);
  dbms_output.put_line(val);
 
EXCEPTION
  WHEN utl_http.end_of_body THEN
    utl_http.end_response(resp);
end;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM