【问题标题】:How to use RCurl to PUT a document into MarkLogic如何使用 RCurl 将文档放入 MarkLogic
【发布时间】:2014-09-15 22:25:00
【问题描述】:

我正在编写一些代码,这些代码将采用数据帧,将其转换为 json 并将其放入 MarkLogic 数据库。下面是在 MarkLogic 中成功创建文档的 curl 命令;

curl --anyauth --user rest-writer:rest-writer -X PUT -d '{"content":"abc"}' 'http://localhost:8003/v1/documents?uri=/json/my.json&format=json

下面的RCurl 代码尝试在 MarkLogic 中创建文档但失败;错误:未经授权

opts <- curlOptions(header = TRUE, userpwd = "rest-writer:rest-writer",httpauth = AUTH_DIGEST)
myURI <- "http://localhost:8003/v1/documents"
myURIput <- paste(myURI, "?uri=/json/myOne.json", sep="")
httpPUT(myURIput, '{"content": "Hello MarkLogic"', .opts = opts)

我退后一步,尝试使用 getURL() 包中的 getURL() 从 MarkLogic 数据库中获取数据;

下面的代码可以正常工作(opts和myURI和上面一样);

myURIget<- paste(myURI,"?uri=/json/myDud.json", sep="")
getURL(myURIget, .opts = opts)

然后我尝试使用来自RCurl 的httpGET 函数;

httpGET(myURIget, .opts = opts)

但我又得到了Error: Unauthorized

我在 r 代码中设置了一些调试选项;

debugfunction = d$update, verbose = TRUE

但结果基本相同。

非常感谢任何意见

【问题讨论】:

  • MarkLogic 的完整版本字符串是什么?
  • MarkLogic 版本为 7.0-2.1

标签: r curl libcurl marklogic rcurl


【解决方案1】:

这是我要使用的 httr 代码

library(httr)

PUT("http://localhost:8003/v1/documents",
  query = list(uri = "/json/myOne.json", format = "json"),
  body = list(content = "Hello MarkLogic"),
  encode = "json",
  authenticate("rest-writer", "rest-writer", "digest")
)

我还会检查您的服务器是否实际使用了digest auth,basic 更常见。

【讨论】:

  • 这行得通。我也让它与 ML 版本 8.0-20140809 一起工作。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-03-10
  • 1970-01-01
  • 1970-01-01
  • 2011-09-01
  • 2017-06-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多