使用oracle utl_http包需要注意的事项
2016-02-16 11:30
302 查看
http://blog.chinaunix.net/uid-411974-id-2167853.html
总结下几次使用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;
总结下几次使用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;
相关文章推荐
- 使用utl_http获取某个http页面内容
- C++网络编程总结
- jmeter测试http接口
- httpclient解析https网页
- 关于Jsoup解析https网页的问题
- php中httpclient的实现方法
- 玩转linux--网络配置
- HttpURLConnection 直接发送soap消息调用webservice
- 大陆网络下如何快速使用Android SDK Manager进行联网更新和下载
- iOS,Android网络抓包教程之tcpdump
- 从谷歌Mozilla态度看https发展
- GET: https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login? loginicon=true &uuid=odcptUu2JA==&tip=0
- Android使用广播监听网络状态变化 一直收到系统广播 广播过滤
- 学习asp.net里的HttpModule
- IOS开发之ASIHTTPRequest下载示例
- 网络安全领域最具代表性的75个安全工具
- virtualbox 内部网络桥接配置
- TCP/IP基础知识
- 忽略ssl使用httpclient访问阿里支付宝
- 2016太原网络营销师搜索引擎(SEO)监控分析