R - Translate GET requests in Postman with body raw to GET requests in R

797 views Asked by At

I have a question about to add body to GET request.

  1. In Postman, I easily add body raw json to tab Body

enter image description here

  1. In R, I use httr::GETand I can not find any option to add them. I try to use option query, but it return error 500 "Missing parameter username"

This is my code (sorry about fake data):

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].\"}"

Can anybody help me to this case? Thank you so much.

1

There are 1 answers

5
ekoam On BEST ANSWER

Try this:

resp <- httr::POST(body = query, encode = "json")