如何在Delphi中发出HTTPS POST请求? [英] How to make an HTTPS POST request in Delphi?

查看:611
本文介绍了如何在Delphi中发出HTTPS POST请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Delphi中执行HTTPS POST请求的最简单方法是什么?我在发出HTTP POST请求时没有问题,但是如何使用SSL?我已经在Google周围搜索了,没有找到足够好的解释。

What is the easiest way to do an HTTPS POST request in Delphi? I'm not having problems with making HTTP POST requests, but how can I do it using SSL? I've googled around and haven't found anything that explains this well enough.

这是我尝试的代码:

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;

当我尝试运行它时,出现以下错误:

When I try to run it I get the following 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'.

我不明白。我发送了参数,尽管错误听起来像是我已经发送了文件。

I don't understand that. I sent parameters, though the errors sounds like I would have sent a file.

我也将libeay32.dll和ssleay32.dll包含在myProject.exe文件夹中。

Also I have included libeay32.dll and ssleay32.dll within my myProject.exe folder.

推荐答案

您没有指定您的Delphi版本或indy版本,但是在将Indy与Delphi 2009和HTTPS捆绑在一起之前,我遇到了一些问题,当我从 indy svn 获得最新消息时,问题就解决了。

You didn't specified your Delphi version or indy version, but I had some problems before with the bundled Indy with Delphi 2009 and HTTPS, and when I got the latest source from indy svn, the problem solved.

这篇关于如何在Delphi中发出HTTPS POST请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆