2010-11-19 28 views
15

Delphi'de bir HTTPS POST isteği yapmanın en kolay yolu nedir? HTTP POST istekleri oluşturmada sorun yaşıyorum, ancak SSL kullanarak nasıl yapabilirim? Etrafa baktım ve bunu yeterince açıklayan bir şey bulamadım. Delphi'de HTTPS POST isteği nasıl yapılır?

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; 

ben aşağıdaki hatayı alıyorum çalıştırmayı deneyin

:

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'. 

ben bunu anlamıyorum

İşte denedim kod. Parametreler gönderdim, ancak hatalar bir dosya gönderirdi.

Ayrıca myproject.exe klasörümdeki libeay32.dll ve ssleay32.dll dosyasını ekledim.

+0

Bunun için bir çözüm buldunuz mu? –

cevap

3

Delphi sürümünüzü veya indy sürümünü belirtmediniz, ancak Delphi 2009 ve HTTPS ile birlikte gelen Indy ile bazı sorunlar yaşadım ve en son kaynağı indy svn'dan aldığımda sorun çözüldü.

1

diğer alternatif Synapse olduğunu.

Bu sınıf kütüphanesi yazının tam kontrol sunuyor, ancak aynı zamanda basit bir liner sonrası yöntemini sunmaktadır:

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

HttpPostURL işleviniz https'yi destekliyor mu? – 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; 

uç;