使用 R 登录 .NET 站点

Login to .NET site using R

我正在尝试使用我的凭据登录到 .NET 站点,但无法正常运行。我的代码的灵感来自于下面的线程

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)

结果:假

请帮助我理解问题

如果您确定您的凭据正确,您可以尝试添加更多额外的 curl setopt 参数,在 PHP 中的 example 之后。 也许也值得尝试监控您的凭据是如何传输的。也许一些额外的编码是必要的或不必要的。

您可以更改选项 'Btn_Login' = 'GO' 到 像

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

根据this,原因是一个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.