HTTP/1.1 400 Bad Request

Giganews Newsgroups
Subject: HTTP/1.1 400 Bad Request
Posted by:  Steve Mitchel (ste…@eventpro.net)
Date: Thu, 27 Sep 2007

I have some code that posts an xml file up to a website along with a user
name and password. When all goes well the web site returns a success in the
response "Status S10: OK". When the web site finds the file is in error is
sends one of many possible errors codes in the response, except I never get
that response. Instead the line where I run my HttpConnection.Post raises an
exception with the following error: "HTTP/1.1 400 Bad Request". The errors
that are being sent from the web site look like they are formatted the same
as the success (ie: "Error E20: Access denied").

I use the BDS 2006 with Indy 10.1.5.

Does anyone know what I may be doing wrong. Below is a simple version of the
code I run.

Thanks
Dave

My Code:

function TransferXML(aFile, aUser, aPassword: String): string;
var
    HttpConnection: TIdHttp;
    streamFormData: TIdMultiPartFormDataStream;
    streamResponse: TStringStream;
begin
    streamFormData  := TIdMultiPartFormDataStream.Create;
    streamResponse  := TStringStream.Create('');
    try
        streamFormData.AddFormField('user', aUser);
        streamFormData.AddFormField('password', aPassword);
        streamFormData.AddFile('comxmlfile', aFile, 'multipart/form-data');
        streamFormData.Position := 0;

        HttpConnection := TIdHttp.Create;
        try
            // the following line raises the exception if the response is
suppose
            // to be an error code but runs fine when the response is a
success code
            HttpConnection.Post(TransferOptions.VenueCheck.Url,
streamFormData, streamResponse);
        finally
            HttpConnection.Free;
        end;

        streamResponse.Position := 0;
        Result    := streamResponse.DataString;
    finally
        streamFormData.Free;
        streamResponse.Free;
  end;
end;

Replies