R中的POST请求参数

时间:2019-03-09 19:43:13

标签: python r post httr

我正在尝试将以POST编写的python请求代码再现为R。代码是

import requests
url = 'https://path/to/url'
auth = ('<username>', '<password>')    
file = 'path/to/myfile.csv'
options = {'category': 'a', 'shared': 'false', 'filename': 'this filename'}
cert = 'myverify.crt'


requests.post(url, auth=auth, files=file, params=options, verify=cert)

R中,我正在使用httr,而我的尝试是

library(httr)
url <- 'https://path/to/url'
usrname <- '<username>'
pswrd <- '<password>'
cert <- 'myverify.crt'    
file <- 'path/to/myfile.csv'
r <- POST(url = url,
      body = list(file = upload_file(file)),
      authenticate(usrname, pswrd, type = "basic"),
      config = list(sslcert = cert),
      verbose())

在上面的代码中,我在哪里像在params中一样传递python。应该是json格式还是list格式。

0 个答案:

没有答案