简体   繁体   English

如何使用Ubuntu中的cURL将XQuery代码发布到MarkLogic?

[英]How to post XQuery code to MarkLogic using cURL from Ubuntu?

I am using Ubuntu machine. 我正在使用Ubuntu机器。 I am doing POST call using curl command and sending xquery code as --data in string format. 我正在使用curl命令进行POST调用,并以字符串格式将xquery代码作为--data发送。 In response I am getting below error: 作为回应我得到以下错误:

xdmp:database()HTTP/1.1 500 REST-UNSUPPORTEDPARAM: (rest:UNSUPPORTEDPARAM) Endpoint does not support query parameter: xdmp:database()

Below is the complete curl command 下面是完整的curl命令

curl -v --digest -u username --request POST "http://host:port/qconsole/endpoints/evaler.xqy?dbid=someid&querytype=xquery&action=eval" --data "xdmp:database()"

In the above command Basically I am trying to run xquery code on the targeted machine (host:port/endpoints/evaler.xqy) 在上面的命令基本上我试图在目标机器上运行xquery代码(主机:端口/端点/ evaler.xqy)

Is this the right way to pass xquery code? 这是传递xquery代码的正确方法吗?

Update: 更新:

I am using ML 7 我正在使用ML 7

After passing the headers I am able to run the XQuery code but facing one more issue. 传递头文件后,我能够运行XQuery代码,但又面临一个问题。

When I am passing "xdmp:database()" as data It's working fine (see the below command), in the response I am getting database ID. 当我传递“xdmp:database()”作为数据它工作正常(参见下面的命令),在响应中我得到数据库ID。

 curl -v --digest -uusername --data "xdmp:database()" --header "Content-type:text/x-www-form-urlencoded" --header "Accept: multipart/mixed; boundary=BOUNDARY" --request POST "http://host:port/qconsole/endpoints/evaler.xqy?dbid=dbid&querytype=xquery&action=eval"

When I tried with passing "let $x := 10 return $x" as data (As given in below command) I am getting 当我尝试传递“let $ x:= 10 return $ x”作为数据时(如下面的命令所示)我得到了

x: undefined variable x:未定义的变量

even not asking for password!! 甚至不要求密码!!

 curl -v --digest -u username --data "let $x := 10 return $x" --header "Content-type:text/x-www-form-urlencoded" --header "Accept: multipart/mixed; boundary=BOUNDARY" --request POST "http://host:port/qconsole/endpoints/evaler.xqy?dbid=dbid&querytype=xquery&action=eval"

Not able to figure it out, What I am doing wrong. 无法弄清楚,我做错了什么。

Please help. 请帮忙。

Here is some example bash that uses cURL to eval JavaScript from stdin. 下面是一些使用cURL从stdin中评估JavaScript的示例bash (Changing to XQuery is just a matter of changing the parameter name.) (更改为XQuery只是更改参数名称的问题。)

#!/usr/bin/env bash

# Pipes stdin as the JavaScript body of a REST Client API eval request
#
# Usage:
#   cat cat mycode.js | awk … | curl … @-
#   pbpaste | awk … | curl … @-

awk '{print "javascript="$0}' | curl http://localhost:8000/v1/eval --digest -u "$USER":"$PASS" -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: multipart/mixed' -d @-

You'll need to set up your $USER and $PASS variables appropriately. 您需要适当地设置$USER$PASS变量。

I think you are better off using the REST endpoint for evaluation: 我认为您最好使用REST端点进行评估:

http://docs.marklogic.com/REST/POST/v1/eval http://docs.marklogic.com/REST/POST/v1/eval

HTH! HTH!

If using MarkLogic 8+, then you should use /v1/eval, as @grtjn noted. 如果使用MarkLogic 8+,则应使用/ v1 / eval,如@grtjn所述。 Since you used the marklogic-7 tag, it looks like you're on ML7. 由于您使用了marklogic-7标记,因此它看起来像是在ML7上。

The top choice, regardless of version, would be to create a REST API extension for whatever this code is supposed to do, assuming you're not trying to support arbitrary XQuery execution. 无论版本如何,最重要的选择是为这个代码应该做的任何事情创建一个REST API扩展 ,假设你没有尝试支持任意XQuery执行。 If you are, you could create an extension that mimics what /v1/eval does. 如果是,您可以创建一个模仿/ v1 / eval所做的扩展。 Better yet, upgrade to ML8 if you can and use /v1/eval itself. 更好的是,如果可以的话,升级到ML8并使用/ v1 / eval本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM