【问题标题】:MarkLogic v1/transactions create by REST APIMarkLogic v1/由 REST API 创建的事务
【发布时间】:2014-09-24 21:33:34
【问题描述】:

我一直在尝试使用此处的开发人员指南通过 MarkLogic REST API (/v1/transactions) 创建事务:https://docs.marklogic.com/REST/POST/v1/transactions

当我尝试调用事务 REST 服务来创建新事务(我正在使用 CURL)时,我会收到以下 HTTP 响应:

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)。

谁能帮我解释一下为什么这个 CURL 语句失败了?

干杯

【问题讨论】:

  • 200 vs 303 可能是您的客户端自动跟随重定向。有时在客户端中禁用它会更容易混淆。

标签: rest transactions marklogic


【解决方案1】:

问题是curl“方便”而不是您的要求。

当您没有为 POST 指定 Content-Type 时,curl“有帮助”默认 Content-Type 为 application/x-www-form-urlencoded

REST API 将 application/x-www-form-urlencoded POST 处理为 GET,因为没有有效负载,只有参数,这就是为什么它看起来像一个错误的请求。

尝试相同的curl 命令,但添加-H 'Content-Type: text/plain' 参数。

希望对你有所帮助

【讨论】:

  • 干杯,成功了。有人也对开发者文档发表了评论,因此其他人应该从这个建议中受益。再次感谢。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多