gpt4 book ai didi

r - 如何使用 header `postForm`

转载 作者:行者123 更新时间:2023-12-02 02:34:06 25 4
gpt4 key购买 nike

如何使用RCurl构造这个POST http请求?

POST http://localhost:7474/db/data/index/node/
Accept: application/json; charset=UTF-8
Content-Type: application/json
{
"name" : "node_auto_index",
"config" : {
"type" : "fulltext",
"provider" : "lucene"
}
}

我在R中想出了这个:

require(RCurl)
httpheader=c(Accept="application/json; charset=UTF-8",
"Content-Type"="application/json")
x = postForm("http://localhost:7474/db/data/index/node/",
.opts=list(httpheader=httpheader),
name="node_auto_index",
config=c(type="fulltext", provider="lucene")
)

这个说法正确吗?

最佳答案

使用 httr 会更容易一些:

library(httr)
POST("http://localhost:7474/db/data/index/node/",
accept_json(),
add_headers("Content-Type" = "application/json"),
body = toJSON(list(
"name" = "node_auto_index",
"config" = list(
"type" = "fulltext",
"provider" = "lucene"
)
))
)

使用开发版本更容易(install_github("hadley/devtools"):

POST("http://localhost:7474/db/data/index/node/",
accept_json(),
body = list(
"name" = "node_auto_index",
"config" = list(
"type" = "fulltext",
"provider" = "lucene"
)
),
encode = "json"
)

关于r - 如何使用 header `postForm`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24387119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com