【发布时间】:2018-03-02 13:49:53
【问题描述】:
按照此处的其他示例,我尝试使用 R 中的 postForm 和 POST 方法来隐藏一些 curl 代码,但是,我遇到了 400 个错误。
这是我要翻译的卷曲:
curl -X POST --header 'Content-Type: application/json;charset=UTF-8' --
header 'Accept: application/json' -d '[
{
"campaignKwType":"DESTINATION_LANDMARK",
"featureId": 9849,
"guid": "xyz",
"language": "ENG",
"lob": "HOTEL",
"matchType": "EXACT",
"posa": "GBR",
"remarketingType": "NEW_CUSTOMERS",
"searchEngine": "GOOGLE",
"superRegionCampRef": true
} ]' 'https://apiaddress'
使用 postForm:
x <- postForm("https://apiaddress",
.opts = list(postfields = toJSON(list(campaignKwType = "DESTINATION_LANDMARK", featureId = 9849, guid = "xyz", language = "ENG", lob = "HOTEL", matchType = "EXACT", posa = "GBR", remarketingType = "NEW_CUSTOMERS", searchEngine = "GOOGLE", superRegionCampRef = TRUE)),
httpheader = c('Content-Type' = 'application/json;charset=UTF-8', Accept = 'application/json')))
使用 POST:
x <- POST("https://apiaddress",
verbose(),
encode = "json",
body = list(c(campaignKwType = "DESTINATION_LANDMARK", featureId = 9849, guid = "xyz", language = "ENG", lob = "HOTEL", matchType = "EXACT", posa = "GBR", remarketingType = "NEW_CUSTOMERS", searchEngine = "GOOGLE", superRegionCampRef = TRUE))
)
不胜感激,我已经使用其他问题作为这两个请求的示例,并且我还检查了 curl 本身的工作原理。谢谢!
【问题讨论】: