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.
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: 2023-08-15 18:20
#> Status: 200
#> Content-Type: text/html; charset=ISO-8859-1
#> Size: 18.3 kB
#> <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" ...
#> var h=this||self;function l(){return void 0!==window.google&&void 0!==w...
#> function t(a,b,c,d,k){var e="";-1===b.search("&ei=")&&(e="&ei="+p(d),-1...
#> document.documentElement.addEventListener("submit",function(b){var a;if...
#> </style><style>body,td,a,p,.h{font-family:arial,sans-serif}body{margin:...
#> var l=this||self;var m,n=null!=(m=l.mei)?m:1,p,q=null!=(p=l.sdo)?p:!0,r...
#> a.fileName;g&&(0<g.indexOf("-extension:/")&&(e=3),c+="&script="+b(g),f&...
#> 0;k<g.length;k++)-1!==g[k].name.indexOf(google.xjsu)&&(h=1),-1!==g[k].n...
#> 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: 2023-08-15 18:20
#> Status: 200
#> Content-Type: text/html; charset=ISO-8859-1
#> Size: 18.3 kB
#> <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" ...
#> var h=this||self;function l(){return void 0!==window.google&&void 0!==w...
#> function t(a,b,c,d,k){var e="";-1===b.search("&ei=")&&(e="&ei="+p(d),-1...
#> document.documentElement.addEventListener("submit",function(b){var a;if...
#> </style><style>body,td,a,p,.h{font-family:arial,sans-serif}body{margin:...
#> var l=this||self;var m,n=null!=(m=l.mei)?m:1,p,q=null!=(p=l.sdo)?p:!0,r...
#> a.fileName;g&&(0<g.indexOf("-extension:/")&&(e=3),c+="&script="+b(g),f&...
#> 0;k<g.length;k++)-1!==g[k].name.indexOf(google.xjsu)&&(h=1),-1!==g[k].n...
#> 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 2024-02-14 18:20:37 NID
#> value
#> 1 511=fkWoQtY4pu6vDN_TLRXm4luAmbSUQj5PWKWmoQmAwt6LrJH3qNx1Qf3enm7nh_C4EVoL1vfSaVnLq3vbkOFCBY2uou8d1QUm16q_Hg6WOv2L2dnV2sBwWOovikCp6ZyYQEzkgAcXBTnJFbyp-S37SFiFaWzL0scZ1P-rxAKDwM4
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 = "")))
}