Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过httr提交显式空参数_R_Curl_Rcurl_Httr - Fatal编程技术网

通过httr提交显式空参数

通过httr提交显式空参数,r,curl,rcurl,httr,R,Curl,Rcurl,Httr,有没有办法通过httr将NULL作为JSON参数提交 当我执行httr::POST(“https://httpbin.org/post“,body=list(a=1,b=NULL),httr::verbose(),encode=“json”),我在输出中看到b=NULL从负载的某个地方被丢弃,即使list(a=1,b=NULL)是一个有效的R列表,其现有的b值设置为NULL 在Python的请求库中,提交无参数是允许的,我使用的API取决于该行为(可能不是最明智的设计选择,但这是我必须接受的)。

有没有办法通过
httr
NULL
作为JSON参数提交

当我执行
httr::POST(“https://httpbin.org/post“,body=list(a=1,b=NULL),httr::verbose(),encode=“json”)
,我在输出中看到
b=NULL
从负载的某个地方被丢弃,即使
list(a=1,b=NULL)
是一个有效的R列表,其现有的
b
值设置为
NULL


在Python的
请求
库中,提交
参数是允许的,我使用的API取决于该行为(可能不是最明智的设计选择,但这是我必须接受的)。有没有办法让
httr
RCurl
或其他东西与此连接?

这似乎是由
身体引起的谢谢!这与我得到的答案也很相似
httr::POST(
  "https://httpbin.org/post",
  body = '{"a":1,"b":"None"}',
  httr::verbose(),
  encode = "json"
)
httr::POST(
  "https://httpbin.org/post",
  body = jsonlite::toJSON(list(a = 1, b = "None"), auto_unbox = TRUE),
  httr::verbose(),
  encode = "json"
)
jsonlite::toJSON(list(a = 1, b = NA), auto_unbox = TRUE)
# {"a":1,"b":null} 

jsonlite::toJSON(list(a = 1, b = NULL), auto_unbox = TRUE)
# {"a":1,"b":{}} 

jsonlite::toJSON(list(a = 1, b = NA_integer_), auto_unbox = TRUE)
# {"a":1,"b":"NA"}

jsonlite::toJSON(list(a = 1, b = list()), auto_unbox = TRUE)
# {"a":1,"b":[]}