Http SSL 的使用

1 篇文章 / 0 new
author
Http SSL 的使用
若採 SSL 請求方式, 使用 TIdHttp 時須在接上 TIdSSLIOHandlerSocketOpenSSL 即可達成, 但須作下配置
1. 需要 libeay32.dll, ssleay32.dll, 可從 http://indy.fulgan.com/SSL/ 下載至於程式目錄下即可.
2. TIdHttp 必要參數, 否則會出現錯誤訊息而收不到回傳資料
HTTPOptions := [hoKeepOrigProtocol];
3. TIdSSLIOHandlerSocketOpenSSL 必要參數
SSLOptions.Method := sslvSSLv3;//是實際格式
SSLOptions.Mode := sslmUnassigned;
var
    responseData: String;
    IdSSLIO: TIdSSLIOHandlerSocketOpenSSL;
begin
    IdSSLIO := IdSSLIOHandlerSocketOpenSSL1;
    IdSSLIO.SSLOptions.Method := sslvSSLv3;
    IdSSLIO.SSLOptions.Mode := sslmUnassigned;
    with IdHTTP1 do
    begin
        ConnectTimeout := 3000;
        HTTPOptions := [hoKeepOrigProtocol,hoForceEncodeParams];//一定要 hoKeepOrigProtocol
        Request.CharSet := 'UTF-8';
        Response.CharSet := 'UTF-8';
    end;
    try
        responseData := IdHTTP1.get('https://127.0.0.1/aa.php')
    except
    end;
    IdHTTP1.Disconnect;
end;
Free Web Hosting