Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Methods with body should get encode argument #103

Closed
hadley opened this issue Apr 22, 2014 · 3 comments
Closed

Methods with body should get encode argument #103

hadley opened this issue Apr 22, 2014 · 3 comments

Comments

@hadley
Copy link
Member

hadley commented Apr 22, 2014

Which can be json, xml, mutlipart or form. Need to preserve existing multipart behaviour (or at least warn)

@krose
Copy link

krose commented May 18, 2014

Is this issue the reason why I can't POST with JSON in the body, but I can with a list?

require(httr)

dst_url <- "http://api.statbank.dk/v1/data"
final_request <- list("table" = "folk1",
                      "lang" = "en",
                      "format" = "CSV",
                      "valuePresentation" = "Default")

## This works
POST(url=dst_url, body=final_request, multipart=FALSE)

## But this doesn't
final_request <- jsonlite::toJSON(x=final_request)
POST(url=dst_url, body=final_request, multipart=FALSE)
POST(url=dst_url, body=final_request, multipart=TRUE)
POST(url=dst_url, body=final_request, multipart=FALSE, add_headers("Content-Type" = "application/json"))
POST(url=dst_url, body=final_request, multipart=TRUE, add_headers("Content-Type" = "application/json"))

@hadley
Copy link
Member Author

hadley commented May 18, 2014

Are you sure that API accepts json? The fact that the first one works suggests that it doesn't.

@krose
Copy link

krose commented May 18, 2014

The API recommends that you POST the requests as JSON, but you can also url encode the requests. It can answer in XML or JSON except for "data" requests (others are table, tableinfo and subject). I thought that I was posting a JSON request in the first POST, but I just found the verbose() function and now see that I don't. I think I'll try to work with the url encoding instead. Thanks!

@hadley hadley closed this as completed in ec156a7 Jun 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants