Login into website using MSXML2.XMLHTTP instead of InternetExplorer.Application with VBA

耗尽温柔 提交于 2019-11-28 07:53:53

It's possible but not that easy.

First you need to use CreateObject("Msxml2.ServerXMLHTTP.6.0") and not CreateObject("MSXML2.XMLHTTP").

Then follow these steps:

  1. Open and send a GET to https://www.nfp.fazenda.sp.gov.br/login.aspx
  2. Parse and store the cookie from the response header "Set-Cookie"
  3. Parse and store the __VIEWSTATE, __VIEWSTATEGENERATOR, __EVENTVALIDATION from the HTML response
  4. Build the data for the next query with the values parsed previously and with your user-name/password :

    __EVENTTARGET:""
    __EVENTARGUMENT:""
    __VIEWSTATE:"..."
    __VIEWSTATEGENERATOR:"..."
    __EVENTVALIDATION:"..."
    ctl00$ddlTipoUsuario:"#rdBtnNaoContribuinte"
    ctl00$UserNameAcessivel:"Digite+o+Usuário"
    ctl00$PasswordAcessivel:"x"
    ctl00$ConteudoPagina$Login1$rblTipo:"rdBtnNaoContribuinte"
    ctl00$ConteudoPagina$Login1$UserName:"..."
    ctl00$ConteudoPagina$Login1$Password:"..."
    ctl00$ConteudoPagina$Login1$Login:"Acessar"
    ctl00$ConteudoPagina$Login1$txtCpfCnpj:"Digite+o+Usuário"
    
  5. Open a POST to https://www.nfp.fazenda.sp.gov.br/login.aspx

  6. Set the header "Cookie" with the cookie parsed at step 2
  7. Set the header Content-Type: "application/x-www-form-urlencoded"
  8. Set the header Content-Length with the length of the data
  9. Send the POST with the data from step 4
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!