Skip to content

This handle preserves settings and cookies across multiple requests. It is the foundation of all requests performed through the httr package, although it will mostly be hidden from the user.

Usage

handle(url, cookies = TRUE)

Arguments

url

full url to site

cookies

DEPRECATED

Note

Because of the way argument dispatch works in R, using handle() in the http methods (See GET()) will cause problems when trying to pass configuration arguments (See examples below). Directly specifying the handle when using http methods is not recommended in general, since the selection of the correct handle is taken care of when the user passes an url (See handle_pool()).

Examples

handle("http://google.com")
#> Host: http://google.com <NA>
handle("https://google.com")
#> Host: https://google.com <NA>

h <- handle("http://google.com")
GET(handle = h)
#> Response [http://www.google.com/]
#>   Date: 2022-08-17 14:41
#>   Status: 200
#>   Content-Type: text/html; charset=ISO-8859-1
#>   Size: 13.9 kB
#> <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" ...
#> var f=this||self;var h,k=[];function l(a){for(var b;a&&(!a.getAttribute...
#> function n(a,b,c,d,g){var e="";c||-1!==b.search("&ei=")||(e="&ei="+l(d)...
#> google.y={};google.sy=[];google.x=function(a,b){if(a)var c=a.id;else{do...
#> document.documentElement.addEventListener("submit",function(b){var a;if...
#> </style><style>body,td,a,p,.h{font-family:arial,sans-serif}body{margin:...
#> var h=this||self;var k,l=null!=(k=h.mei)?k:1,n,p=null!=(n=h.sdo)?n:!0,q...
#> a.fileName;g&&(0<g.indexOf("-extension:/")&&(e=3),c+="&script="+b(g),f&...
#> if (!iesg){document.f&&document.f.q.focus();document.gbqf&&document.gbq...
#> }
#> ...
# Should see cookies sent back to server
GET(handle = h, config = verbose())
#> Response [http://www.google.com/]
#>   Date: 2022-08-17 14:41
#>   Status: 200
#>   Content-Type: text/html; charset=ISO-8859-1
#>   Size: 13.9 kB
#> <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" ...
#> var f=this||self;var h,k=[];function l(a){for(var b;a&&(!a.getAttribute...
#> function n(a,b,c,d,g){var e="";c||-1!==b.search("&ei=")||(e="&ei="+l(d)...
#> google.y={};google.sy=[];google.x=function(a,b){if(a)var c=a.id;else{do...
#> document.documentElement.addEventListener("submit",function(b){var a;if...
#> </style><style>body,td,a,p,.h{font-family:arial,sans-serif}body{margin:...
#> var h=this||self;var k,l=null!=(k=h.mei)?k:1,n,p=null!=(n=h.sdo)?n:!0,q...
#> a.fileName;g&&(0<g.indexOf("-extension:/")&&(e=3),c+="&script="+b(g),f&...
#> if (!iesg){document.f&&document.f.q.focus();document.gbqf&&document.gbq...
#> }
#> ...

h <- handle("http://google.com", cookies = FALSE)
#> Warning: Cookies argument is deprecated
GET(handle = h)$cookies
#>                  domain flag path secure          expiration name
#> 1 #HttpOnly_.google.com TRUE    /  FALSE 2023-02-16 14:41:50  NID
#>                                                                                                                                                                             value
#> 1 511=Twux3MgR3BoAWSkyaiVDD-knp6b1f1c22l_2_oYQHqwn1Mlrm1-i7fCGvoDeEU1o-XybMxhFx_5l2yM3TLuA9wnj5fRZE51mzqIvHLAPYKgM-E92ddIuwznPe4kzcYkcwU1OuRFW88y_ZLYimq9NMvKMA7taByON8d8CocOzLGs
if (FALSE) {
# Using the preferred way of configuring the http methods
# will not work when using handle():
GET(handle = h, timeout(10))
# Passing named arguments will work properly:
GET(handle = h, config = list(timeout(10), add_headers(Accept = "")))
}