使用 Indy TIdHTTP 发布问题 [英] Post problems with Indy TIdHTTP

查看:30
本文介绍了使用 Indy TIdHTTP 发布问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Indy 的 TIdHTTP 向亚马逊的 SES 服务发帖时遇到问题.

I am having issues posting to Amazon's SES Service using Indy's TIdHTTP.

这是我使用的代码示例:

Here is an example of the code i am using:

procedure TMainFrm.btnAmazonSESClick(Sender: TObject);
var
  SSLHandler: TIdSSLIOHandlerSocket;
  HttpClient: TIdHTTP;  
  Params: TStringStream;
begin
  SSLHandler := TIdSSLIOHandlerSocket.Create(Self);
  HttpClient := TIdHTTP.Create(Self);  
  Params := TStringStream.create('');
  try
    with SSLHandler do
      SSLOptions.Method := sslvSSLv3
    with HttpClient do
    begin
      IOHandler := SSLHandler;
      AllowCookies := True;
      HandleRedirects := True;
      HTTPOptions := [hoForceEncodeParams];
      Request.ContentType := 'application/x-www-form-urlencoded';
    end;

    PageMemo.Text := HttpClient.Post('https://email.us-east-1.amazonaws.com?Action=VerifyEmailAddress&AWSAccessKeyId=012Some123Key46&EmailAddress=test@test%2Ecom', Params);

  finally
    SSLHandler.Free;
    HttpClient.Free; 
    Params.Free;
  end;
end;

结果

  • 在 Indy 10.5.7 下,我收到错误:HTTP/1.1 404 Not Found

  • Under Indy 10.5.7 I get the error: HTTP/1.1 404 Not Found

在 Indy 9.0.14 下出现错误:Socket Error # 11004

Under Indy 9.0.14 I get the error: Socket Error # 11004

调试试验

  • 同样的演示可以成功地从 HTTPS 网页中获取 HTML.

  • This same demo can successfully GET the HTML from an HTTPS web page.

如果我将上面的 URL 粘贴到浏览器中,它会显示预期的 XML 结果.

If i paste the URL above into a browser it displays the expected XML result.

如果您对此有任何建议,我将不胜感激.

I would appreciate any advice on the cause.

推荐答案

这篇文章只是一个不完整的猜测.

也许 Remy 可能会帮助您纠正它.使用以下代码,我收到了 HTTP/1.1 400 错误请求,但我并不想知道,因为 API 参考Common Query Parameters 至少需要您为请求创建的数字签名,我不知道该怎么做.

Maybe Remy might help you to correct it. With the following code I'm getting HTTP/1.1 400 Bad Request but I'm not wondering because the API reference talks about Common Query Parameters where is at least required the digital signature you'll create for the request what I don't know how to do.

我根本无法测试这个,因为我在那里没有帐户.但我认为

I can't test this at all because I have no account there. But I think the

procedure TForm1.Button1Click(Sender: TObject);
var
  HTTPClient: TIdHTTP;
  Parameters: TStrings;
  SSLHandler: TIdSSLIOHandlerSocketOpenSSL;

begin
  SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  HTTPClient := TIdHTTP.Create(nil);
  Parameters := TStringList.Create;

  try
    SSLHandler.SSLOptions.Method := sslvSSLv3;
    SSLHandler.SSLOptions.Mode := sslmUnassigned;

    HTTPClient.IOHandler := SSLHandler;
    HTTPClient.HTTPOptions := [hoForceEncodeParams];
    HTTPClient.Request.ContentType := 'application/x-www-form-urlencoded';

    Parameters.Add('Action=VerifyEmailAddress');
    Parameters.Add('EmailAddress=test@test.com');
    Parameters.Add('AWSAccessKeyId=012Some123Key46');
    Parameters.Add('SignatureVersion=2');
    Parameters.Add('Expires='); // ???
    Parameters.Add('Signature='); // ???

    PageMemo.Text := HTTPClient.Post('https://email.us-east-1.amazonaws.com', Parameters);

  finally
    SSLHandler.Free;
    HTTPClient.Free; 
    Parameters.Free;
  end;
end;

这篇关于使用 Indy TIdHTTP 发布问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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