PL/SQL utl_http 获取 xml

发布于 2024-12-12 05:01:10 字数 1691 浏览 0 评论 0原文

我正在尝试实现一个非常简单的 PL/SQL 过程,能够从网络获取 xml 文件。

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;
/

我通过 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.

这很奇怪,因为我想读取的 xml 文件如下:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
    <body>Don't forget me this weekend!</body>
</note>

鉴于相同的代码,没有 _ set_header_ 函数 可以工作对于普通的 HTML 来说很好,正确提供了它的源页面,请有人解释一下为什么它不能与简单的 xml 文件一起使用?

I am trying to implement a very simple PL/SQL procedure able to get an xml file from the web.

The PL/SQL code is the following one:

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:

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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁对谁错谁最难过 2024-12-19 05:01:10

为什么要在 GET 请求中设置 content-type 和 content-length ?您的 GET 请求不能有任何正文(请求实体)。这不是一个帖子。

utl_http.set_header(req, 'content-type', 'text/xml;charset=UTF-8');   
utl_http.set_header(req, 'content-length', length(txt));

你必须这样做才能得到回应。

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.

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.

白色秋天 2024-12-19 05:01:10

从您对 lkuty 答案的问题看来,您正在寻找 接受标头。这通知服务器您将接受什么类型的响应。

It appears from your question on lkuty's answer that you are looking for the Accept header. This informs the server what type(s) you will accept in response.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文