使用postFrom或POST将代码卷曲到R.

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用postFrom或POST将代码卷曲到R.相关的知识,希望对你有一定的参考价值。

我已经尝试使用R中的postForm和POST方法来隐藏一些卷曲代码,这里有一些其他示例,但是,我遇到了400个错误。

这是我要翻译的Curl:

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

非常感谢任何指针,我已经使用其他问题作为这两个请求的示例,我也检查了卷曲本身的工作原理。谢谢!

答案

我不知道为什么你在c()版本的list()中有POST,但我想这不是你想要的。只是用

x <- POST("https://apiaddress",
           verbose(),
           encode = "json",
           body = list(list(campaignKwType = "DESTINATION_LANDMARK", featureId = 9849,  guid = "xyz", language = "ENG", lob = "HOTEL", matchType = "EXACT", posa = "GBR", remarketingType = "NEW_CUSTOMERS", searchEngine = "GOOGLE", superRegionCampRef = TRUE))
           )

以上是关于使用postFrom或POST将代码卷曲到R.的主要内容,如果未能解决你的问题,请参考以下文章

将命令卷曲到 html 或 vb.net

$.ajax$.postfrom表单序列化工具

PHP 卷曲,POST JSON

如何将文件上传到盒子?我有卷曲代码

处理大卷曲响应 - PHP

将 cacert 卷曲到 Java HttpClient 等效项