I'm trying to send a post request using Indy but I am facing some problems. In a form I have TIdHTTP, a TIdSSLIOHandlerSocketOpenSSL and a TIdCookieManager whith these properties:
TIdHTTP:
IdHTTP1.IOHandler := FSSLIO;
IdHTTP1.AllowCookies := True;
IdHTTP1.HandleRedirects := True;
IdHTTP1.ProxyParams.BasicAuthentication := False;
IdHTTP1.ProxyParams.ProxyPort := 0;
IdHTTP1.Request.ContentLength := -1;
IdHTTP1.Request.Accept := 'text/html, */*';
IdHTTP1.Request.BasicAuthentication := False;
IdHTTP1.Request.UserAgent := 'Mozilla/3.0 (compatible; Indy Library)';
IdHTTP1.HTTPOptions := [hoKeepOrigProtocol, hoForceEncodeParams];
IdHTTP1.OnRedirect := IdHTTP1Redirect;
IdHTTP1.CookieManager := IdCookieManager1;
TIdSSLIOHandlerSocketOpenSSL: default values
TIdCookieManager: default values
OnRedirect procedure:
Handled := True;
In a button the following request:
Params := TStringStream.Create('asdf=asdf',TEncoding.UTF8);
edtmemo1.Text := IdHTTP1.Post('https://www.detran.mg.gov.br/habilitacao/1-habilitacao-quero-ser-condutor/consultar-resultado-exame-legislacao/-/busca_resultado_exames/', Params);
Params.Free;
But returns error with response code 301, but the wierd part is that the location is the same url that I am trying to send, so it enter in an infinite loop.
Response
HTTP/1.1 301 Moved Permanently
Date: Thu, 31 Aug 2017 20:23:32 GMT
Server: Apache
X-Powered-By: PHP/5.3.5
P3P: CP="A politica de privacidade deve estar disponivel no site ou pode ser solicitada via fale conosco."
Set-Cookie: SECCCAKEPHP=e19ttp30m5380ih41qal0gipg2; expires=Sat, 09-Sep-2017 04:23:32 GMT; path=/
Location: https://www.detran.mg.gov.br/habilitacao/1-habilitacao-quero-ser-condutor/consultar-resultado-exame-legislacao/-/busca_resultado_exames/
Cache-Control: max-age=604800
Expires: Thu, 07 Sep 2017 20:23:32 GMT
Content-Length: 0
Content-Type: text/html; charset=utf-8
Curl test:
curl -vv -X POST -F 'asdf=asdf' https://www.detran.mg.gov.br/habilitacao/1-habilitacao-quero-ser-condutor/consultar-resultado-exame-legislacao/-/busca_resultado_exames/
I tried the same request using curl and works with response code 200. Any idea of what could be happening?
TIdHTTP
sends. To sniff curl's HTTPS traffic, you can use Fiddler. To sniffTIdHTTP
's HTTPS traffic, you can assign aTIdLog...
component, such asTIdLogFile
, to theTIdHTTP.Intercept
property. DoesTIdHTTP
send back that cookie? – Remy LebeauParams
are you passing toTIdHTTP.Post()
? Please provide a minimal reproducible example showing everything you are actually doing to reproduce the issue. Also, Delphi 2010 is 8 years old, are you using an equally old version of Indy? At the time of this writing, the current Indy version is 10.6.2.5434. – Remy LebeauTIdHTTP
logic does not match you curl logic. I posted an answer explaining the difference. – Remy Lebeau