R - 将 Postman 中带有 body raw 的 GET 请求转换为 R 中的 GET 请求
R - Translate GET requests in Postman with body raw to GET requests in R
我对将正文添加到 GET 请求有疑问。
- 在 Postman 中,我很容易将 body raw json 添加到选项卡 Body
- 在 R 中,我使用
httr::GET
但我找不到任何添加它们的选项。我尝试使用选项 query
,但它 return 错误 500“缺少参数用户名”
这是我的代码(抱歉有假数据):
library(httr)
api <- ".........................../users/authorize"
query <- list("username": "xxxxx", "password": "xxxxxxxxxxxx")
resp <- GET(api, query = query)
stop_for_status(resp)
# Error: Internal Server Error (HTTP 500).
content(resp, type = "text", encoding = "utf-8")
# [1] "{\"status\":\"0\",\"error_code\":\"S002\",\"errors\":\"Missing param [username].\"}"
谁能帮我解决这个问题?非常感谢。
试试这个:
resp <- httr::POST(body = query, encode = "json")
我对将正文添加到 GET 请求有疑问。
- 在 Postman 中,我很容易将 body raw json 添加到选项卡 Body
- 在 R 中,我使用
httr::GET
但我找不到任何添加它们的选项。我尝试使用选项query
,但它 return 错误 500“缺少参数用户名”
这是我的代码(抱歉有假数据):
library(httr)
api <- ".........................../users/authorize"
query <- list("username": "xxxxx", "password": "xxxxxxxxxxxx")
resp <- GET(api, query = query)
stop_for_status(resp)
# Error: Internal Server Error (HTTP 500).
content(resp, type = "text", encoding = "utf-8")
# [1] "{\"status\":\"0\",\"error_code\":\"S002\",\"errors\":\"Missing param [username].\"}"
谁能帮我解决这个问题?非常感谢。
试试这个:
resp <- httr::POST(body = query, encode = "json")