Rcurl with http data post

醉酒当歌 提交于 2019-12-10 22:24:09

问题


I would like to move the following curl call to Rcurl:

curl  'http://myserver.org/stream' 
-H 'Authorization: Basic XXXXXXXX' -H 'Connection: keep-alive' --data-binary '{"limit": 20}' 
-H 'Content-Type: application/json;charset=UTF-8'

This is one of my R tests:

library(RCurl)
url.opts <- list(httpheader = list(Authorization ="Basic XXXXXXXX", 
                Connection = "keep-alive", 
                "Content-Type" = "application/json;charset=UTF-8"))

getURLContent('http://myserver.org/stream', .opts=url.opts)

Now I am missing an attribute to add --data or --data-binary. How to add this option?

Thanks a lot Markus


回答1:


Thanks a lot @hadley.

This is my working solution:

library(httr)
user <- "test"
password <- "test123"
POST(url = 'http://myserver.org/stream', 
     config = c(authenticate(user, password, "basic"), 
                add_headers(Connection = "keep-alive"), 
                accept_json()), 
     body = "{'username':'test'}")


来源:https://stackoverflow.com/questions/18493767/rcurl-with-http-data-post

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!