Skip to content

Instantly share code, notes, and snippets.

@mlist
Created December 13, 2013 12:45
Show Gist options
  • Save mlist/7943747 to your computer and use it in GitHub Desktop.
Save mlist/7943747 to your computer and use it in GitHub Desktop.
how to use RCurl to access a grails controller
authenticate <- function(baseUrl="http://localhost:8080/GrailsApp/", user, password, verbose=F){
require(RCurl)
loginUrl = paste(baseUrl, "login/auth", sep="")
authenticateUrl = paste(baseUrl, "j_spring_security_check", sep="")
cat(paste("trying to authenticate user", user))
agent="Mozilla/5.0"
#Set RCurl pars
curl = getCurlHandle()
curlSetOpt(ssl.verifypeer=FALSE, timeout=60, cookiefile=tempfile(), cookiejar=tempfile(), useragent = agent, followlocation = TRUE, curl=curl, verbose=verbose)
#open login page
getURL(loginUrl, curl=curl)
#Post login form
postForm(authenticateUrl, .params= list(j_username=user, j_password=password), curl=curl, style="POST")
return(curl)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment