什么是Python comamnd requests.post()的R副本?

时间:2018-01-24 15:39:39

标签: python r

用户可能知道R但需要运行以下python代码

import requests
import json

query = "asthma"
r = requests.post("https://ndar.nih.gov/api/search/nda_sw_removal/collection/full", query)

collections = json.loads(r.text)
collections

使用R库,如何在R中重写request.post调用? 挑战是python对query参数的确切作用。

2 个答案:

答案 0 :(得分:2)

我猜您正在寻找类似httr的内容:

取自here的例子:

b2 <- "http://httpbin.org/post"
POST(b2, body = "A simple text string")

取自here的另一个例子:

r <- POST("http://httpbin.org/post", body = list(a = 1, b = 2, c = 3))

基于Slam在评论中提出的建议:

另一个参考来源:http://httr.r-lib.org/reference/POST.html

答案 1 :(得分:0)

library(httr)
query = "asthma"
r = POST("https://ndar.nih.gov/api/search/nda_sw_removal/collection/full", body=query)
library(jsonlite)
aa<-fromJSON(content(r,'text'))
str(aa)
View(aa$collection$results)