GET a url.

GET(url = NULL, config = list(), ..., handle = NULL)

Arguments

url

the url of the page to retrieve

config

Additional configuration settings such as http authentication (authenticate()), additional headers (add_headers()), cookies (set_cookies()) etc. See config() for full details and list of helpers.

...

Further named parameters, such as query, path, etc, passed on to modify_url(). Unnamed parameters will be combined with config().

handle

The handle to use with this request. If not supplied, will be retrieved and reused from the handle_pool() based on the scheme, hostname and port of the url. By default httr requests to the same scheme/host/port combo. This substantially reduces connection time, and ensures that cookies are maintained over multiple requests to the same host. See handle_pool() for more details.

Value

A response() object.

RFC2616

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.

The semantics of the GET method change to a "conditional GET" if the request message includes an If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field. A conditional GET method requests that the entity be transferred only under the circumstances described by the conditional header field(s). The conditional GET method is intended to reduce unnecessary network usage by allowing cached entities to be refreshed without requiring multiple requests or transferring data already held by the client.

The semantics of the GET method change to a "partial GET" if the request message includes a Range header field. A partial GET requests that only part of the entity be transferred, as described in http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35 The partial GET method is intended to reduce unnecessary network usage by allowing partially-retrieved entities to be completed without transferring data already held by the client.

See also

Other http methods: BROWSE, DELETE, HEAD, PATCH, POST, PUT, VERB

Examples

GET("http://google.com/")
#> Response [http://www.google.com/] #> Date: 2018-12-17 20:44 #> Status: 200 #> Content-Type: text/html; charset=ISO-8859-1 #> Size: 12.3 kB #> <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="... #> </style><style>body,td,a,p,.h{font-family:arial,sans-serif}body{margin:0;over... #> if (!iesg){document.f&&document.f.q.focus();document.gbqf&&document.gbqf.q.fo... #> } #> })();</script><div id="mngb"> <div id=gbar><nobr><b class=gb1>Search</b> <a c...
GET("http://google.com/", path = "search")
#> Response [http://www.google.com/webhp] #> Date: 2018-12-17 20:44 #> Status: 200 #> Content-Type: text/html; charset=ISO-8859-1 #> Size: 12.3 kB #> <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="... #> </style><style>body,td,a,p,.h{font-family:arial,sans-serif}body{margin:0;over... #> if (!iesg){document.f&&document.f.q.focus();document.gbqf&&document.gbqf.q.fo... #> } #> })();</script><div id="mngb"> <div id=gbar><nobr><b class=gb1>Search</b> <a c...
GET("http://google.com/", path = "search", query = list(q = "ham"))
#> Response [http://www.google.com/search?q=ham] #> Date: 2018-12-17 20:44 #> Status: 200 #> Content-Type: text/html; charset=ISO-8859-1 #> Size: 59.7 kB #> <!doctype html><html itemscope="" itemtype="http://schema.org/SearchResultsPa... #> </style><style>.star{float:left;margin-top:1px;overflow:hidden}.ybhkme{font-s... #> breasts and other premium meats, as well as heat-and-serve sides, lunch, <br> #> catering&nbsp;...</span><br><div class="osl"><a href="/url?q=https://www.hone... #> without smoking. As a processed meat, the term &quot;<b>ham</b>&quot; include... #> ... Here are our five favorite ways to glaze and caramelize the holiday dinn... #> ... All <b>Ham</b> Recipes Ideas.</span><br></div></div><div class="g"><h3 c... #> the classic, 1942, Ernst Lubitch comedy film, &quot;To Be or Not to Be,&quot;... #> &nbsp;...</span><br></div></div><div class="g"><h3 class="r"><a href="/url?q=... #> specialty <b>hams</b>.</span><br></div></div><div class="g"><h3 class="r"><a ... #> ...
# See what GET is doing with httpbin.org url <- "http://httpbin.org/get" GET(url)
#> Response [http://httpbin.org/get] #> Date: 2018-12-17 20:44 #> Status: 200 #> Content-Type: application/json #> Size: 331 B #> { #> "args": {}, #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "gzip, deflate", #> "Connection": "close", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.43.0 r-curl/3.2 httr/1.4.0.9000" #> }, #> "origin": "35.192.136.167", #> ...
GET(url, add_headers(a = 1, b = 2))
#> Response [http://httpbin.org/get] #> Date: 2018-12-17 20:44 #> Status: 200 #> Content-Type: application/json #> Size: 361 B #> { #> "args": {}, #> "headers": { #> "A": "1", #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "gzip, deflate", #> "B": "2", #> "Connection": "close", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.43.0 r-curl/3.2 httr/1.4.0.9000" #> ...
GET(url, set_cookies(a = 1, b = 2))
#> Response [http://httpbin.org/get] #> Date: 2018-12-17 20:44 #> Status: 200 #> Content-Type: application/json #> Size: 357 B #> { #> "args": {}, #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "gzip, deflate", #> "Connection": "close", #> "Cookie": "a=1;b=2", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.43.0 r-curl/3.2 httr/1.4.0.9000" #> }, #> ...
GET(url, add_headers(a = 1, b = 2), set_cookies(a = 1, b = 2))
#> Response [http://httpbin.org/get] #> Date: 2018-12-17 20:44 #> Status: 200 #> Content-Type: application/json #> Size: 387 B #> { #> "args": {}, #> "headers": { #> "A": "1", #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "gzip, deflate", #> "B": "2", #> "Connection": "close", #> "Cookie": "a=1;b=2", #> "Host": "httpbin.org", #> ...
GET(url, authenticate("username", "password"))
#> Response [http://httpbin.org/get] #> Date: 2018-12-17 20:44 #> Status: 200 #> Content-Type: application/json #> Size: 387 B #> { #> "args": {}, #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "gzip, deflate", #> "Authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", #> "Connection": "close", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.43.0 r-curl/3.2 httr/1.4.0.9000" #> }, #> ...
GET(url, verbose())
#> Response [http://httpbin.org/get] #> Date: 2018-12-17 20:44 #> Status: 200 #> Content-Type: application/json #> Size: 331 B #> { #> "args": {}, #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "gzip, deflate", #> "Connection": "close", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.43.0 r-curl/3.2 httr/1.4.0.9000" #> }, #> "origin": "35.192.136.167", #> ...
# You might want to manually specify the handle so you can have multiple # independent logins to the same website. google <- handle("http://google.com") GET(handle = google, path = "/")
#> Response [http://www.google.com/] #> Date: 2018-12-17 20:44 #> Status: 200 #> Content-Type: text/html; charset=ISO-8859-1 #> Size: 12.3 kB #> <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="... #> </style><style>body,td,a,p,.h{font-family:arial,sans-serif}body{margin:0;over... #> if (!iesg){document.f&&document.f.q.focus();document.gbqf&&document.gbqf.q.fo... #> } #> })();</script><div id="mngb"> <div id=gbar><nobr><b class=gb1>Search</b> <a c...
GET(handle = google, path = "search")
#> Response [http://www.google.com/webhp] #> Date: 2018-12-17 20:44 #> Status: 200 #> Content-Type: text/html; charset=ISO-8859-1 #> Size: 12.3 kB #> <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="... #> </style><style>body,td,a,p,.h{font-family:arial,sans-serif}body{margin:0;over... #> if (!iesg){document.f&&document.f.q.focus();document.gbqf&&document.gbqf.q.fo... #> } #> })();</script><div id="mngb"> <div id=gbar><nobr><b class=gb1>Search</b> <a c...