我想接收一个 json 字符串 作为来自 REST API URL 的响应。
它有
标题为Content-Type=application/json
。
它应该有一个 json 格式的主体
例如-{"string1":"string2","string3":"string4"}
这些是我在使用 POSTMAN 时输入的详细信息。上述要求的正确语法是什么。
我正在尝试以下语法,但它总是会引发错误:
POST(url = login,add_headers('Content-Type'='application/json'),body = c("string1"="string2","string3"="string4"),encode = c("json"),verbose())
最佳答案
尝试使用这个
POST(url = login,add_headers('Content-Type'='application/json'),body = list(string1="string2",string3="string4"),encode = "json",verbose())
关于json - httr 库中的 POST 方法与 R 中的特定 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42803429/