2010-11-19 45 views
15

¿Cuál es la forma más fácil de hacer una solicitud de POST HTTPS en Delphi? No estoy teniendo problemas para realizar solicitudes HTTP POST, pero ¿cómo puedo hacerlo mediante SSL? He buscado en Google y no he encontrado nada que lo explique lo suficiente.¿Cómo hacer una solicitud POST HTTPS en Delphi?

Aquí está el código que he intentado:

procedure TForm1.FormCreate(Sender: TObject); 
var 
    responseXML:TMemoryStream; 
    responseFromServer:string; 
begin 
    responseXML := TMemoryStream.Create; 
    IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(self); 
    with idSSLIOHandlerSocketOpenSSL1 do 
    begin 
     SSLOptions.Method := sslvSSLv2; 
     SSLOptions.Mode := sslmUnassigned; 
     SSLOptions.VerifyMode := []; 
     SSLOptions.VerifyDepth := 0; 
     host := ''; 
    end; 

    IdHTTP1 := TIdHTTP.Create(Self); 
    with IdHTTP1 do 
    begin 
     IOHandler := IdSSLIOHandlerSocketOpenSSL1; 
     AllowCookies := True; 
     ProxyParams.BasicAuthentication := False; 
     ProxyParams.ProxyPort := 0; 
     Request.ContentLength := -1; 
     Request.ContentRangeEnd := 0; 
     Request.ContentRangeStart := 0; 
     Request.Accept := 'text/html, */*'; 
     Request.BasicAuthentication := False; 
     Request.UserAgent := 'Mozilla/3.0 (compatible; Indy Library)'; 
     HTTPOptions := [hoForceEncodeParams]; 
    end; 
    responsefromserver := IdHTTP1.Post('https://.../','name1=value1&name2=value2&....'); 
end; 

Cuando trato de ejecutarlo me sale el siguiente error:

Project myProject.exe raised exception class EFOpenError with message 'Cannot open file "C:\...\Projects\Debug\Win32\name1=value1name2=value2 The system cannot find the file specified'. 

no entiendo eso. Envié los parámetros, aunque los errores suenan como si hubiera enviado un archivo.

También he incluido libeay32.dll y ssleay32.dll dentro de mi carpeta myProject.exe.

+0

¿Alguna vez encontró una solución para esto? –

Respuesta

3

No especificó su versión de Delphi o su versión indy, pero tuve algunos problemas antes con el paquete Indy con Delphi 2009 y HTTPS, y cuando obtuve la última fuente de indy svn, el problema se solucionó.

1

Otra alternativa a Indy es Synapse.

Esta biblioteca de clases ofrece un control completo de la entrada, pero también ofrece un método post un trazador de líneas simple también:

function HttpPostURL(const URL, URLData: string; const Data: TStream): Boolean; 
+0

¿Su función HttpPostURL es compatible con https? – Ampere

1

http://chee-yang.blogspot.com/2008/03/using-indy-https-client-to-consume.html

var S: TStringList; 
    M: TStream; 
begin 
S := TStringList.Create; 
M := TMemoryStream.Create; 
try 
    S.Values['Email'] := 'your google account'; 
    S.Values['Passwd'] := 'your password'; 
    S.Values['source'] := 'estream-sqloffice-1.1.1.1'; 
    S.Values['service'] := 'cl'; 

    IdHTTP1.IOHandler := IdSSLIOHandlerSocketOpenSSL1; 
    IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded'; 
    IdHTTP1.Post('https://www.google.com/accounts/ClientLogin', S, M); 
    Memo1.Lines.Add(Format('Response Code: %d', [IdHTTP1.ResponseCode])); 
    Memo1.Lines.Add(Format('Response Text: %s', [IdHTTP1.ResponseText])); 

    M.Position := 0; 
    S.LoadFromStream(M); 
    Memo1.Lines.AddStrings(S); 
finally 
    S.Free; 
    M.Free; 
end; 

final;

Cuestiones relacionadas