Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- curl --dump-header cook.txt ^
- --data "RURL=http=//www.example.com/r&user=bob&password=hello" ^
- --user-agent "Mozilla/5.0" ^
- http://www.example.com/login
- HTTP/1.1 302 Found
- Date: Thu, ******
- Server: Microsoft-IIS/6.0
- SERVER: ******
- X-Powered-By: ASP.NET
- X-AspNet-Version: 1.1.4322
- Location: ******
- Set-Cookie: Cookie1=; domain=******; expires=****** ******
- ******
- ******
- Cache-Control: private
- Content-Type: text/html; charset=iso-8859-1
- Content-Length: 189
- library(httr)
- POST("http://www.example.com/login",
- body= list(RURL="http=//www.example.com/r",
- user="bob", password="hello"),
- user_agent("Mozilla/5.0"))
- Response [http://www.example.com/error]
- Status: 411
- Content-type: text/html
- <h1>Length Required</h1>
- library(RCurl)
- curl <- getCurlHandle()
- curlSetOpt(cookiejar="/tmp/cookies.txt", curl=curl)
- postForm("http://example.com/login", login="mylogin", passwd="mypasswd", curl=curl)
- getURL("http://example.com/anotherpage", curl=curl)
- GET("http://httpbin.org/cookies/set?a=1")
- # Response [http://httpbin.org/cookies]
- # Status: 200
- # Content-type: application/json
- # {
- # "cookies": {
- # "a": "1"
- # }
- # }
- GET("http://httpbin.org/cookies")
- # Response [http://httpbin.org/cookies]
- # Status: 200
- # Content-type: application/json
- # {
- # "cookies": {
- # "a": "1"
- # }
- # }
- ### RCurl login and browse private pages ###
- library("RCurl")
- loginurl ="http=//www.*****"
- mainurl ="http=//www.*****"
- agent ="Mozilla/5.0"
- #User account data and other login pars
- pars=list(
- RURL="http=//www.*****",
- Username="*****",
- Password="*****"
- )
- #RCurl pars
- curl = getCurlHandle()
- curlSetOpt(cookiejar="cookiesk.txt", useragent = agent, followlocation = TRUE, curl=curl)
- #or simply
- #curlSetOpt(cookiejar="", useragent = agent, followlocation = TRUE, curl=curl)
- #post login form
- web=postForm(loginurl, .params = pars, curl=curl)
- #go to main url with real data
- web=getURL(mainurl, curl=curl)
- #parse/print content of web
- #..... etc. etc.
- #This has the side effect of saving cookie data to the cookiejar file
- rm(curl)
- gc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement