oracle PL/SQL utl_http 获取 xml
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7914736/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PL/SQL utl_http get xml
提问by Raffaello
I am trying to implement a very simple PL/SQL
procedure able to get an xml
file from the web.
我正在尝试实现一个非常简单的PL/SQL
过程,能够xml
从网络获取文件。
The PL/SQL
code is the following one:
该PL/SQL
代码是以下之一:
SET serveroutput ON SIZE 40000
set escape on
create or replace procedure testProc as
url VARCHAR2(256) := 'http://www.mypage.com/testXML.xml';
req sys.utl_http.req;
resp sys.utl_http.resp;
txt VARCHAR2(100);
begin
req := sys.utl_http.begin_request(url,'GET','HTTP/1.0');
utl_http.set_header(req, 'content-type', 'text/xml;charset=UTF-8');
utl_http.set_header(req, 'content-length', length(txt));
resp := sys.utl_http.get_response(req);
LOOP
sys.utl_http.read_line(resp, txt, TRUE);
dbms_output.put_line(txt);
END LOOP;
sys.utl_http.end_response(resp);
EXCEPTION WHEN sys.utl_http.end_of_body THEN
sys.utl_http.end_response(resp);
end testProc;
/
I successfully built the procedure by SQLPlus. However when I try to execute it I get the following error:
我成功地通过 SQLPlus 构建了该过程。但是,当我尝试执行它时,出现以下错误:
SQL> exec testProc;
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>413 Request Entity Too Large</title>
</head><body>
<h1>Request Entity Too Large</h1>
The requested resource<br />/trentad/testXML.xml<br />
does not allow request data with GET requests, or the amount of data provided in
the request exceeds the capacity limit.
</body></html>
PL/SQL procedure successfully completed.
This is weird as the xml file I'd like to read is the following one:
这很奇怪,因为我想阅读的 xml 文件如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<body>Don't forget me this weekend!</body>
</note>
Given that the same code, without the _ set_header_ functions
works fine for a normal HTML
, providing correctly its source page, please could anybody explain me why it does not work with a simple xml
file?
鉴于相同的代码,没有_ set_header_ functions
正常工作正常HTML
,正确提供其源页面,请谁能解释我为什么它不适用于简单xml
文件?
回答by Ludovic Kuty
Why do you set content-type and content-length in your GET request ? Your GET request can't have any body (request entity). It is not a POST.
为什么要在 GET 请求中设置 content-type 和 content-length?您的 GET 请求不能有任何正文(请求实体)。它不是 POST。
utl_http.set_header(req, 'content-type', 'text/xml;charset=UTF-8');
utl_http.set_header(req, 'content-length', length(txt));
You have to do this for response.
你必须这样做才能做出回应。