REST API创建的MarkLogic v1/事务 [英] MarkLogic v1/transactions create by REST API
问题描述
我一直在尝试使用此处的开发人员指南通过MarkLogic REST API(/v1/transactions)创建事务:
I have been trying to create a transaction via the MarkLogic REST API (/v1/transactions) using the Developer guidance here: https://docs.marklogic.com/REST/POST/v1/transactions
当我尝试调用事务REST服务以创建新事务时(我正在使用CURL),然后收到以下HTTP响应:
When I try to call the transaction REST service to create a new transaction (I am using CURL), then I receive the following HTTP Response:
curl -X POST -d "" -i --anyauth --user user:password http://localhost:7010/v1/transactions
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Digest realm="public", ...
Content-type: application/xml
Server: MarkLogic
Content-Length: 211
Connection: Keep-Alive
Keep-Alive: timeout=5
HTTP/1.1 400 Bad Request
Content-type: application/xml
Server: MarkLogic
Content-Length: 316
Connection: Keep-Alive
Keep-Alive: timeout=5
<rapi:error xmlns:rapi="http://marklogic.com/rest-api">
<rapi:status-code>400</rapi:status-code><rapi:status>Bad Request</rapi:status>
<rapi:message-code>REST-INVALIDPARAM</rapi:message-code>
<rapi:message>REST-INVALIDPARAM: (err:FOER0000) Invalid parameter: could not parse transaction id </rapi:message>
</rapi:error>
有趣的是,当我在Chrome中使用POSTMAN时,我可以创建事务,但是响应与预期的不同(响应为 200 状态,并且XML详细说明了事务,而不是 303 响应,并且"Location"标头设置为交易ID).
Interestingly, when I use POSTMAN within Chrome, I can create the transaction, but the response is different to that expected (It response with 200 status and with XML detailing the transaction, rather than a 303 response and the "Location" header set to the transaction ID).
有人可以帮助我解释为什么此CURL语句失败吗?
Can anyone help me explain why this CURL statement is failing?
欢呼
推荐答案
问题是curl
"方便",而不是您的请求.
The problem is a curl
"convenience" and not your request.
如果您未为 POST 指定内容类型,则curl
有帮助"会将内容类型默认为application/x-www-form-urlencoded
When you don't specify the Content-Type for a POST, curl
"helpfully" defaults the Content-Type to application/x-www-form-urlencoded
REST API
将application/x-www-form-urlencoded
POST
作为GET
处理,因为没有有效载荷,只有参数,这就是为什么它看起来像是错误请求的原因.
The REST API
processes a application/x-www-form-urlencoded
POST
as a GET
because there is no payload, only parameters, which is why it looks like a bad request.
尝试相同的curl
命令,但添加-H 'Content-Type: text/plain'
自变量.
Try the same curl
command but adding a -H 'Content-Type: text/plain'
argument.
希望有帮助
这篇关于REST API创建的MarkLogic v1/事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!