- 用户卷曲等效于httr

时间:2017-06-29 12:58:30

标签: r curl httr

我认为,这是一些非常简单的卷曲代码,我试图将其翻译成httr格式。

curl -X POST \
  --user '<email>:<password>' \
  --header 'user-key: <user_key>' \
  --url https://api.m.com/v1/clients

到目前为止,我已经尝试了

library(httr)    
POST(url = "https://api.m.com/v1/clients",
                 add_headers('user-key' = "userkey",
                             user = 'email:password'))

但没有成功。这里有什么错误吗?卷曲代码中是否有等同于--user的httr?

1 个答案:

答案 0 :(得分:6)

library(httr)  

username <- 'my_user_name'
password <- 'my_password'

POST(url = "https://api.m.com/v1/clients", 
                 config = authenticate(username, password), add_headers("Content-Type: application/json"),
                 body = upload_file('./my_file.json'),
                 encode = 'json')