Build an equivalent R request for a curl request
Asked Answered
M

1

6

I have the following curl request:

curl --request GET --header "key: value" http://urlhere

How can I run the request in R?

Mundane answered 22/4, 2015 at 10:26 Comment(0)
R
8

You can use the GET function:

library(httr)
r <- GET("http://urlhere", add_headers(key = value))

add_headers allows you to add header data to your request.

If you use ?GET you can see more information and options.

Raulrausch answered 22/4, 2015 at 10:36 Comment(2)
Thanks for the quick help. I tried it but I am getting Status: 401 as response to the request. Could this be some permissions issue?Mundane
Yep, 401 is unauthorized error code. More info on List of HTTP status codesRaulrausch

© 2022 - 2024 — McMap. All rights reserved.