如何通过 HTTP Post 事务将 XML 检索到 Oracle PL/SQL 中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/452475/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 17:42:43  来源:igfitidea点击:

How to retrieve XML into Oracle PL/SQL via an HTTP Post transaction?

oracleweb-servicesplsqlmod-plsql

提问by MojoMark

I'm trying to implement the "blog this" function from Flickr using the BloggerAPI to my pl/sql based CMS.

我正在尝试使用 BloggerAPI 将 Flickr 中的“博客此”功能实现到我的基于 pl/sql 的 CMS。

When Flickr sends me the posting transaction, the HTTP transaction looks like this:

当 Flickr 向我发送发布事务时,HTTP 事务如下所示:

POST /pls/website/!pkg.procAPI HTTP/1.1
Host: www.mydomain.com
Accept: */*
User-Agent: Flickr
Content-Type: text/xml; charset=utf-8
Content-Length: 1220
Expect: 100-continue

<?xml version="1.0" encoding="utf-8"?>
<methodCall>
    <methodName>blogger.newPost</methodName>
    <params>
        <param><value><string>NO_APP_KEY</string></value></param>
        <param><value><string>1</string></value></param>
        <param><value><string>markj</string></value></param>
        <param><value><string>markj</string></value></param>
        <param><value><string>This is a test post from &lt;a href=&quot;http://www.flickr.com/r/testpost&quot;&gt;&lt;img alt=&quot;flickr&quot; src=&quot;http://www.flickr.com/images/flickr_logo_blog.gif&quot; width=&quot;41&quot; height=&quot;18&quot; border=&quot;0&quot; align=&quot;absmiddle&quot; /&gt;&lt;/a&gt;, a fancy photo sharing thing.</string></value></param>
        <param><value><boolean>1</boolean></value></param>
    </params>
</methodCall>

But my server is responding with an HTTP-400 Bad Request and the error message is "Signature Mismatch or Missing '='" and my pl/sql procedure never gets a chance to process the request. I suspect that the flexible parameter passing is getting hosed when looking at the message, but I don't know how else

但是我的服务器正在响应 HTTP-400 错误请求,错误消息是“签名不匹配或缺少‘=’”,我的 pl/sql 过程永远没有机会处理请求。我怀疑在查看消息时,灵活的参数传递会受到影响,但我不知道还有什么办法

The process to get the available blogs seems to work ok, but the content of the request doesn't have all the html entities as part of the message:

获取可用博客的过程似乎工作正常,但请求的内容没有将所有 html 实体作为消息的一部分:

    POST /pls/website/!pkg.procAPI HTTP/1.1
Host: www.mydomain.com
Accept: */*
User-Agent: Flickr
Content-Type: text/xml; charset=utf-8
Content-Length: 304

<?xml version="1.0" encoding="utf-8"?>
<methodCall>
    <methodName>blogger.getUsersBlogs</methodName>
    <params>
        <param><value><string>NO-APP-KEY</string></value></param>
        <param><value><string>mark</string></value></param>
        <param><value><string>markj</string></value></param>
    </params>
</methodCall>

Is there a way to get the xml data from the body of the http request directly? or some other approach I'm over looking?

有没有办法直接从http请求的正文中获取xml数据?或者我正在寻找的其他方法?

Thanks, Mark.

谢谢,马克。

采纳答案by MojoMark

I opened a service request with Oracle and they confirmed that mod_plsql does not support retrieving httpheader variables. Here is the discussion I had on the SR:

我向 Oracle 发起了一个服务请求,他们确认 mod_plsql 不支持检索 httpheader 变量。这是我在 SR 上的讨论:

ISSUE ANALYSIS

问题分析

I need to confirm it, but Mark conclusion so far looks right to me,i.e. MOD_PLSQL is always invoking and processing PLSQL procedures and there is no way to read the raw HTTP request because MOD_PLSQL parses the request and checks if there is a PLSQL procedure with this name and if there are arguments to pass. If there are no arguments to pass but we are providing something else like the XML document, MODPLSQL gets puzzled and thinks this is a new pair of parameter and value when this is not really the case.

我需要确认一下,但到目前为止马克结论对我来说是正确的,即 MOD_PLSQL 总是调用和处理 PLSQL 过程,并且无法读取原始 HTTP 请求,因为 MOD_PLSQL 解析请求并检查是否有 PLSQL 过程这个名字,如果有参数要传递。如果没有要传递的参数,但我们提供了类似 XML 文档的其他内容,MODPLSQL 会感到困惑,并认为这是一对新的参数和值,而事实并非如此。

ANSWER

回答

No, it is not possible to do it because MOD_PLSQL just treats requests with parameters which can be parsed and translated as a PLSQL procedure call with several arguments. MOD_PLSQL has no concept of a "httprequest" variable containing the whole request in the same way java has the HTTPRequest object

不,这是不可能的,因为 MOD_PLSQL 只处理带有参数的请求,这些参数可以被解析和转换为带有多个参数的 PLSQL 过程调用。MOD_PLSQL 没有包含整个请求的“httprequest”变量的概念,就像 java 拥有 HTTPRequest 对象一样

ISSUE ANALYSIS

问题分析

Got the confirmation unless we pass it as a parameter we can not read it from MOD_PLSQL. In other words, if we pass the XML page in the HTTP request body we need to use something like java where we can treat the request in raw mode and we can read any HTTP header and the http body without restrictions of any kind.

得到确认,除非我们将它作为参数传递,否则我们无法从 MOD_PLSQL 读取它。换句话说,如果我们在 HTTP 请求正文中传递 XML 页面,我们需要使用类似 java 的东西,我们可以在原始模式下处理请求,并且我们可以不受任何限制地读取任何 HTTP 标头和 http 正文。

回答by John Flack

Can the xml be sent as a file attachment? In other words change:

xml 可以作为文件附件发送吗?换句话说,改变:

Content-Type: text/xml; charset=utf-8

Content-Type: text/xml; charset=utf-8

to

Content-Type: multipart/form-data, boundary=AaB03x

Content-Type: multipart/form-data, boundary=AaB03x

Then add this before the xml:

然后在xml之前添加:

--AaB03x content-disposition: form-data; name="xmlfile"; filename="myfile.xml"
Content-Type: text/xml

--AaB03x content-disposition: form-data; name="xmlfile"; filename="myfile.xml"
Content-Type: text/xml

And this after the xml:

这在 xml 之后:

--AaB03x--

--AaB03x--

Now, you set up the procedure for a file upload, as explained in this article: Files, Uploads, and Downloads with Web PLSQL

现在,您设置文件上传的过程,如本文所述: 使用 Web PLSQL 的文件、上传和下载

回答by Mark Harrison

Use UTL_HTTP

使用 UTL_HTTP

You can use the UTL_HTTP package to do this.

您可以使用 UTL_HTTP 包来执行此操作。

UTL_HTTP.read_text(
   r     IN OUT NOCOPY resp,
   data  OUT NOCOPY VARCHAR2,
   len   IN PLS_INTEGER DEFAULT NULL);

"The UTL_HTTP package supports HTTP 1.1 chunked transfer-encoding. When the response body is returned in chunked transfer-encoding format as indicated in the response header, the package automatically decodes the chunks and returns the response body in de-chunked format."

“UTL_HTTP 包支持 HTTP 1.1 分块传输编码。当响应主体以响应标头中指示的分块传输编码格式返回时,包自动解码块并以去块格式返回响应主体。”

http://download.oracle.com/docs/cd/B10500_01/appdev.920/a96612/u_http.htm

http://download.oracle.com/docs/cd/B10500_01/appdev.920/a96612/u_http.htm

回答by Mark Harrison

I'm encountering the same issue MojoMark was (though with a different external application). MojoMark's follow up comment is correct, the read_text information does not answer the question.

我遇到了与 MojoMark 相同的问题(尽管使用了不同的外部应用程序)。MojoMark 的后续评论是正确的,read_text 信息没有回答问题。

Like MojoMark, I am attempting to RECEIVE a POST from an external entity. The PLSQL I'm trying to write is to receive that POST and store it.

像 MojoMark 一样,我试图从外部实体接收 POST。我正在尝试编写的 PLSQL 是接收该 POST 并存储它。

I was able to write the outbound POST XML with no problem, but have been unable to set up a procedure to receive it.

我能够毫无问题地编写出站 POST XML,但无法设置接收它的过程。

The issue appears to be the PLSQL procedure wants a variable name, ie: http://server/modplsql/testload, POST "data='data'"

问题似乎是 PLSQL 过程需要一个变量名,即: http://server/modplsql/testload, POST "data='data'"

However, the body of the POST is just an XML data stream, no "=" assigning a value to a parameter, so the function gets the "Mismatch or Missing '='"" error.

但是,POST 的主体只是一个 XML 数据流,没有“=”为参数赋值,因此该函数会收到“不匹配或缺少 '='””错误。

It seems like there should be a way to tell MODPLSQL to just accept accept the post data like a "typical" function call, but I think I'm missing something obvious.

似乎应该有一种方法可以告诉 MODPLSQL 只接受像“典型”函数调用一样接受发布数据,但我想我遗漏了一些明显的东西。

The basics function I'm trying to use to receive the post is: procedure testload ( DATA in clob ) as BEGIN htp.print('Input POST stream was ' || DATA )
end testload;

我试图用来接收帖子的基本功能是:procedure testload ( DATA in clob ) as BEGIN htp.print('Input POST stream was ' || DATA )
end testload;

回答by Adam Hawkes

The only significant difference I can see between the two requests is the "Expect: 100-continue" business. This appers to be a clause in the HTTP 1.1 specification which allows the client to split the request in two. Basically, the client sends the header to the server, and the server must make a choice. If it is "happy" with the header it will give a HTTP 100 response to indicate that the rest of the message will be accepted.

我能看到的两个请求之间的唯一显着区别是“期望:100-继续”业务。这似乎是 HTTP 1.1 规范中的一个条款,它允许客户端将请求一分为二。基本上,客户端将标头发送到服务器,服务器必须做出选择。如果它对标头“满意”,它将给出 HTTP 100 响应以指示将接受消息的其余部分。

Since you're getting data from Flickr, I'm not sure what level of control you have over the http requests being made by the client. From the server side it may be necessary to make a configuration change to Apache, or it may be a bug in mod_plsql that's popping up with the "!" flexible parameter marker.

由于您从 Flickr 获取数据,我不确定您对客户端发出的 http 请求的控制级别。从服务器端,可能需要对 Apache 进行配置更改,或者可能是 mod_plsql 中的一个错误,它弹出了“!” 灵活的参数标记。

Either way, the current blogger api is not like this. You probably should move to the new GData API.

不管怎样,现在的博主api都不是这样的。您可能应该转向新的 GData API。