Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1980458
  • 博文数量: 148
  • 博客积分: 7697
  • 博客等级: 少将
  • 技术积分: 3071
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-10 23:04
个人简介

MiBDP,数据开发、项目团队、数据应用和产品在路上,金融保险、互联网网游、电商、新零售行业、大数据和AI在路上。对数仓、模型、ETL、数据产品应用了解。DTCC 2013演讲嘉宾,曾做过两款大获好评的数据产品平台。知识星球ID:35863277

文章分类
文章存档

2020年(1)

2019年(2)

2017年(2)

2016年(5)

2015年(1)

2014年(1)

2013年(6)

2012年(5)

2011年(24)

2010年(28)

2009年(1)

2008年(6)

2007年(30)

2006年(36)

分类: Oracle

2011-08-11 16:23:48

总结下几次使用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('' ||
                                 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;


阅读(16997) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~