0

我有一个 RestXQ 方法:

declare
    %rest:path("/doSomething")
    %rest:POST
    %rest:form-param("name","{$name}")
    function page:doSomething($name as document-node())
    {
        (: Code... :)
    };

我试图通过 XForms 向这个方法发送一个 POST 请求。作为对客户端的响应,[XPTY0004] Cannot convert empty-sequence() to document-node(): ().我尝试删除document-node()但参数 $name 只是空的。

请求参数如下所示:

<data xmlns=""><name>Test</name></data>

有什么解决办法吗?

4

1 回答 1

1

问题在于%rest:form-param("name","{$name}")键值对,但您的方法表明您想要$name as document-node(). 这两件事放在一起没有意义。

而不是form-param您可能想要 POST 请求的正文,为此您将使用以下内容:

declare
  %rest:path("/doSomething")
  %rest:POST("{$body}")
function page:doSomething($body as document-node())
{
    (: Code... :)
};

http://www.adamretter.org.uk/papers/restful-xquery_january-2012.xhtml#media-example

于 2018-08-26T06:08:42.417 回答