Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login to .NET site using R

Tags:

r

rcurl

httr

I am trying to login with my credentials to a .NET site but unable to get it working. My code is inspired from the below thread

How to login and then download a file from aspx web pages with R

library(RCurl)
curl = getCurlHandle()
curlSetOpt(cookiejar = 'cookies.txt', followlocation = TRUE, autoreferer = TRUE, curl = curl)
html <- getURL('http://www.aceanalyser.com/Login.aspx', curl = curl)
viewstate <- as.character(sub('.*id="__VIEWSTATE" value="([0-9a-zA-Z+/=]*).*', '\\1', html))
viewstategenerator <- as.character(sub('.*id="__VIEWSTATEGENERATOR" value="([0-9a-zA-Z+/=]*).*', '\\1', html))

params <- list(
  'txtUserID'    = '********',
  'txtPwd'    = '*******',
  'Btn_Login' = 'GO',
  '__VIEWSTATE' = viewstate,
  '__VIEWSTATEGENERATOR' = viewstategenerator,
  'HiddenField1' = '1280',
  'HiddenField2' = '700',
  'Hdn_Pwd' = 'true')

html = postForm('http://www.aceanalyser.com/Login.aspx', .params = params, curl = curl)
grepl('Logout', html)

Result: FALSE

Please help me understand the issue

like image 882
Sushanta Deb Avatar asked Jul 28 '17 12:07

Sushanta Deb


2 Answers

You may change the option 'Btn_Login' = 'GO' to something like

'Btn_Login.x' = '22',
'Btn_Login.y' = '14'

According to this, the reason is a bug.

Some browsers (IIRC it is just some versions of Internet Explorer) only send the co-ordinates of the image map (in name.x and name.y) and ignore the value.

like image 81
aristotll Avatar answered Nov 21 '22 06:11

aristotll


If you are sure your credentials are correct you could try to add more additional curl setopt arguments, following this example in PHP. It's maybe also worth a try to monitor how your credentials are transferred. Maybe some extra encoding is necessary or unnecessary one added.

like image 40
wp78de Avatar answered Nov 21 '22 06:11

wp78de