delphi - indy 9 returning a 404 error when POSTing to https .aspx page -
i'm using indy 9 tidhttp component tidssliohandlersocket post aspx page (https://www.thedogs.co.nz/catch-the-action/results.aspx) emulate happens in browser view specific months race results. code below should download results november 2015.
first, url parse extract values __viewstate (thevs), __viewstategenerator (thevsg) , __eventvalidation (theev).
then this:
with http begin allowcookies := true; proxyparams.basicauthentication := false; proxyparams.proxyport := 0; request.contentlength := -1; request.contentrangeend := 0; request.contentrangestart := 0; request.accept := 'text/html, */*'; request.useragent := 'mozilla/5.0 (windows nt 10.0; rv:42.0)gecko/20100101 firefox/42.0'; request.contenttype:= 'application/x-www-form-urlencoded'; request.contentencoding := 'utf-8'; httpoptions := [hoforceencodeparams]; end; sl tstringlist, m tmemorystream.
sl.add('__viewstate="' + thevs + '"&'); sl.add('__viewstategenerator="' + thevsg + '"&'); sl.add('__eventvalidation="' + theev + '"&'); sl.add( 'txtcurrentdate="1/12/2015%2012:00:00%20a.m."&'); sl.add( 'txtaction="prevmonth"'); url := 'https://www.thedogs.co.nz/catch-the-action/results.aspx'; http.post( url, sl, m ); showmessage( 'sent' ); assignfile( f, '.\downloaded\theresults' ); rewrite( f ); m.position := 0; sl.loadfromstream(m); x := 0 sl.count - 1 writeln( f, sl[ x ] ); closefile( f ); all exception
http/1.1 404 not found
any appreciated!!
you not formatting tstringlist content correctly. need rid of " , & characters, , not url-encode values. post() handles of internally when formatting actual http request.
you setting request properties not need set, or setting invalid values.
after get() page retreive cookies , viewstate data, on subsequent requests, not setting request.referer property same url. time link or form on 1 page used access page, referer header needs set accordingly. servers validate make sure requests coming right place.
try this:
with http begin allowcookies := true; proxyparams.basicauthentication := false; proxyparams.proxyport := 0; request.accept := 'text/html, */*'; request.useragent := 'mozilla/5.0 (windows nt 10.0; rv:42.0)gecko/20100101 firefox/42.0'; httpoptions := [hoforceencodeparams]; end; url := 'https://www.thedogs.co.nz/catch-the-action/results.aspx'; ... := http.get(url, ...); // parse html needed... sl.add('__viewstate=' + thevs); sl.add('__viewstategenerator=' + thevsg); sl.add('__eventvalidation=' + theev); sl.add( 'txtcurrentdate=1/12/2015 12:00:00 a.m.'); sl.add( 'txtaction=prevmonth'); http.request.referer := url; http.post( url, sl, m ); m.position := 0; sl.loadfromstream(m); sl.savetofile( '.\downloaded\theresults' ); // or simply: m.savetofile( '.\downloaded\theresults' );
Comments
Post a Comment