http - 301 status code after PostForm -
i trying write program login ahrefs.com
, parse data. @ first sending request ahrefs.com
cookies , html parse needed token:
client := &http.client{} jar := &myjar{} jar.jar = make(map[string] []*http.cookie) client.jar = jar resp, _ := client.get("https://ahrefs.com") root, _ := html.parse(resp.body) element, _ := getelementbyname("_token", root) token := "" _, := range element.attr { if a.key == "value" { token = a.val } }
then sending post request using postform
ahrefs.com/user/login/
. fill fields correct data (tested via browser). when submit form in browser has field return_to
value of main page of site, should redirect ahrefs.com/dashboard/metrics/
(the page want parse data). program's behavior different. after postform
got 301
status code:
resp, _ = client.postform( "https://ahrefs.com/user/login/", url.values{ "email": {"djviman@gmail.com"}, "password": {"aau4bqrxfc4zevu"}, "_token": {token}, "return_to": {"https://ahrefs.com/"}, }) log.println(resp.status) resp.body.close()
then sending request ahrefs.com/dashboard/metrics/
redirects me home page, i'm not logged in:
resp, _ = client.get("https://ahrefs.com/") log.println(resp.status) resp.body.close()
questions are: doing wrong? , hot log in site?
Comments
Post a Comment