记一次使用utl_http方法调用接口,报字符或值错误
2017-07-10 13:33
573 查看
背景:ebs系统和其他系统通过utl_http包调用接口,使用log方法记录日志。
某次调用接口,执行到记录日志行报字符或值错误。
查找原因,发现是p_str的长度超过的32767的限制。
解决办法:
参考:
http://www.orafaq.com/forum/t/202946/
某次调用接口,执行到记录日志行报字符或值错误。
查找原因,发现是p_str的长度超过的32767的限制。
解决办法:
PROCEDURE log(p_str VARCHAR2) IS BEGIN fnd_file.put_line(fnd_file.log, p_str); dbms_output.put_line(p_str); END;
--解决l_messge_clob长度超过32767导致的溢出问题,字符或值错误 FOR i IN 0 .. trunc((dbms_lob.getlength(l_messge_clob) - 1) / l_step) LOOP log(dbms_lob.substr(l_messge_clob, l_step, i * l_step + 1)); END LOOP; --同样 utl_http.write_text 长度不能超过32767, buffer VARCHAR2(2000); offset NUMBER := 1; amount NUMBER := 1024; --解决l_messge_clob长度超过3276导致的溢出问题,字符或值错误 ---utl_http.write_text(l_req, p_content);
UTL_HTTP.SET_BODY_CHARSET('UTF-8');
WHILE (offset < v_req_length) LOOP dbms_lob.read(p_content, amount, offset, buffer); utl_http.write_text(r => l_req, data => buffer); offset := offset + amount; END LOOP;
DECLARE v_doc_fin CLOB := ''; req utl_http.req; res utl_http.resp; url VARCHAR2(1900) := 'url xxx'; v_value VARCHAR2(4000); vchunkdata VARCHAR2(2000); v_req_length NUMBER; buffer VARCHAR2(32767); offset NUMBER := 1; amount NUMBER := 32767; utl_err VARCHAR2(1000); BEGIN IF v_doc_fin IS NOT NULL THEN --v_doc_fin is JSON DOC of CLOB data type from a procedure v_req_length := dbms_lob.getlength(v_doc_fin); dbms_output.put_line(v_req_length); req := utl_http.begin_request(url, 'POST', 'HTTP/1.1'); utl_http.set_header(req, 'Content-Length', v_req_length); utl_http.set_header(req, 'user-agent', 'mozilla/4.0'); utl_http.set_header(req, 'content-type', 'application/json;charset=UTF-8'); utl_http.set_header(req, 'Transfer-Encoding', 'chunked'); utl_http.set_body_charset('UTF-8'); WHILE (offset < v_req_length) LOOP dbms_lob.read(v_doc_fin, amount, offset, buffer); utl_http.write_text(r => req, data => buffer); offset := offset + amount; END LOOP; res := utl_http.get_response(req); BEGIN LOOP utl_http.read_line(res, v_value); dbms_output.put_line(v_value); END LOOP; utl_http.end_response(res); EXCEPTION WHEN utl_http.end_of_body THEN utl_http.end_response(res); WHEN utl_http.too_many_requests THEN utl_http.end_response(res); WHEN OTHERS THEN dbms_output.put_line(utl_http.get_detailed_sqlerrm); dbms_output.put_line(dbms_utility.format_error_stack); dbms_output.put_line(dbms_utility.format_error_backtrace); dbms_output.put_line(dbms_utility.format_call_stack); END; END IF; EXCEPTION WHEN OTHERS THEN utl_http.end_response(res); utl_err := utl_http.get_detailed_sqlerrm; END;
参考:
Oracle 通过UTL_HTTP 发送http请求并处理发送内容中包含空格和特殊字符的问题
utl_http request and response stops when > 32k
UTTL_HTTP to POST CLOB requesthttp://www.orafaq.com/forum/t/202946/
相关文章推荐
- 使用 HttpWebRequest的psot方式传参数调用接口方法
- Java中使用HttpRequest调用RESTfull的DELETE方法接口提示:How to fix HTTP method DELETE doesn't support output
- android使用ksoap2调用webservice接口返回错误HTTP status: 500
- 深入Atlas系列:Web Sevices Access in Atlas示例(4) - 使用HTTP GET调用Web Services方法
- 使用接口调用多个动态Module的同一方法
- C# 调用httpwatch接口基础使用方法
- 使用HttpClient进行http post/get方法的调用,以及使用dom4j解析xml
- 《转》使用httpclient实现http接口调用实例
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(4):异步通讯层生成的客户端代理类、使用HTTP GET进行调用
- 使用Ajax.dll前台调用后台方法及错误示例
- 使用httpclient实现http接口调用实例
- Asp.Net : 捕捉和记录网站中出现的所有未处理错误,抛出详细的页面来源和访问ip,调用的接口方法及异常实例(记事本日志,系统日志及数据库日志)
- 用httpWebRequest调用https开头的php webservice,报“基础连接已经关闭: 未能为SSL/TLS 安全通道建立信任关系”错误的解决方法
- 如何使用单元测试 测试WEB组件方法中的含有Session、Cookie等HttpContext功能调用的方法? 转
- servlet中使用service()方法出现错误:HTTP method POST is not supported by this URL
- 《实战AJAX》中重构的xmlhttpRequest调用的使用方法
- 使用HTTP GET调用Web Services方法
- c++ builder 使用indy http调用webservice方法
- 使用Geoprocessor导出ArcSde中的数据,对COM 组件的调用返回了错误 HRESULT E_FAIL 的解决方法
- 使用jdbc调用oracle b294 存储过程(返回cursor)的错误及解决方法- -