0
votes

Having read all the problems with 403 errors and trying the fixes, I still get the 403 error with the following URL and code. The two SSL DLL files are present in the directory, and the file being used, uploaddata.txt is in the working directory. It is Delphi 7 with Indy 9.

URL:

https://mws.amazonservices.com/?AWSAccessKeyId=A*&Action=SubmitFeed&FeedType=_POST_FLAT_FILE_INVLOADER_DATA_&Merchant=A*&PurgeAndReplace=false&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-07-20T21%3A39%3A28Z&Version=2009-01-01&Signature=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.

Thanks for any help. There are two of us having this problem, one in the U.S. and one in the U.K.

1

1 Answers

1
votes

403 means you are trying to access a URL that you do not have access to. So either you are missing a required authentication step, or the authentication you are providing is wrong.