https提交时出现Indy 9 403错误

时间:2012-07-20 22:50:49

标签: delphi delphi-7

阅读了403错误的所有问题并尝试修复后,我仍然会收到以下URL和代码的403错误。这两个SSL DLL文件存在于目录中,正在使用的文件uploaddata.txt位于工作目录中。它是带有Indy 9的Delphi 7。

网址:

https://mws.amazonservices.com/?AWSAccessKeyId=A *&安培;动作= SubmitFeed&安培;的FeedType = _POST_FLAT_FILE_INVLOADER_DATA_&安培;商家= A * &安培; PurgeAndReplace =假安培;是SignatureMethod = HmacSHA256&安培; SignatureVersion = 2及时间戳= 2012-07- 20T21%3A39%3A28Z&安培;版本= 2009-01-01&安培;签名= MRJFSuBsqdUE7SaoUFdXO5zY2YFOc4QjVxg0lOISSis%3D

unit MWSDemo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, HTTPApp, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdHTTP, IdIOHandler, IdIOHandlerSocket,
  IdSSLOpenSSL, IdServerIOHandler, IdAntiFreezeBase, IdAntiFreeze,
  IdMultipartFormData;

type
  TForm1 = class(TForm)
  Button1: TButton;
  HTTPS: TIdHTTP;
  IdAntiFreeze1: TIdAntiFreeze;
  IdServerIOHandlerSSL1: TIdServerIOHandlerSSL;
  IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocket;
  Memo1: TMemo;
  procedure Button1Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses hash, hmac, sha256, mem_util;

function GetMWSRequest : string;
var
  ctx: THMAC_Context;
   < more code here>
var
  UTC: TSystemTime;
begin
  GetSystemTime(UTC);
  AmazonTimestamp:=HTTPDecode(Format('%.2d', [UTC.wYear]) + '-' 
    + Format('%.2d',         [UTC.wMonth]) + '-' +  Format('%.2d', [UTC.wDay]) + 'T'
    + Format('%.2d', [UTC.wHour]) + ':' + Format('%.2d',  [UTC.wMinute]) + ':' + 
    Format('%.2d', [UTC.wSecond]) + 'Z');
  AmazonURL:='https://mws.amazonservices.com/?';
      < more code here>
  Result:=AmazonURL;
end;

procedure TForm1.Button1Click(Sender: TObject);
var URL, Response: string;
    Stream : TStringStream;
    Params: TIdMultipartFormDataStream;
begin
  URL := GetMWSRequest;
  HTTPS.Request.BasicAuthentication := true;
  HTTPS.Request.ContentType := 'text/html';
  IdSSLIOHandlerSocket1.SSLOptions.Method := TIdSSLVersion(sslvSSLv23);
  HTTPS.IOHandler := IdSSLIOHandlerSocket1;
  try
      Stream := TStringStream.Create('');
      Params := TIdMultipartFormDataStream.Create;
      Params.AddFile('File1', 'UploadData.txt','application/octet-stream');
    try
      HTTPS.Post(URL, Params, Stream);
      Memo2.Text := HTTPS.ResponseText;
    finally
      Stream.Free;
      Params.Free;
    end;
  except
       on E: Exception do
         ShowMessage('** Error: ' + e.Message);
  end;
end;

end.

interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, HTTPApp, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, IdIOHandler, IdIOHandlerSocket, IdSSLOpenSSL, IdServerIOHandler, IdAntiFreezeBase, IdAntiFreeze, IdMultipartFormData; type TForm1 = class(TForm) Button1: TButton; HTTPS: TIdHTTP; IdAntiFreeze1: TIdAntiFreeze; IdServerIOHandlerSSL1: TIdServerIOHandlerSSL; IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocket; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses hash, hmac, sha256, mem_util; function GetMWSRequest : string; var ctx: THMAC_Context; < more code here> var UTC: TSystemTime; begin GetSystemTime(UTC); AmazonTimestamp:=HTTPDecode(Format('%.2d', [UTC.wYear]) + '-' + Format('%.2d', [UTC.wMonth]) + '-' + Format('%.2d', [UTC.wDay]) + 'T' + Format('%.2d', [UTC.wHour]) + ':' + Format('%.2d', [UTC.wMinute]) + ':' + Format('%.2d', [UTC.wSecond]) + 'Z'); AmazonURL:='https://mws.amazonservices.com/?'; < more code here> Result:=AmazonURL; end; procedure TForm1.Button1Click(Sender: TObject); var URL, Response: string; Stream : TStringStream; Params: TIdMultipartFormDataStream; begin URL := GetMWSRequest; HTTPS.Request.BasicAuthentication := true; HTTPS.Request.ContentType := 'text/html'; IdSSLIOHandlerSocket1.SSLOptions.Method := TIdSSLVersion(sslvSSLv23); HTTPS.IOHandler := IdSSLIOHandlerSocket1; try Stream := TStringStream.Create(''); Params := TIdMultipartFormDataStream.Create; Params.AddFile('File1', 'UploadData.txt','application/octet-stream'); try HTTPS.Post(URL, Params, Stream); Memo2.Text := HTTPS.ResponseText; finally Stream.Free; Params.Free; end; except on E: Exception do ShowMessage('** Error: ' + e.Message); end; end; end.

感谢您的帮助。我们有两个人遇到这个问题,一个在美国,一个在英国。

1 个答案:

答案 0 :(得分:1)

403表示您正在尝试访问您无权访问的URL。因此,要么您缺少必需的身份验证步骤,要么您提供的身份验证错误。

相关问题