Re: HTTP/1.1 400 Bad Request

Giganews Newsgroups
Subject: Re: HTTP/1.1 400 Bad Request
Posted by:  Remy Lebeau \(Indy Team\) (no.spam@no.spam.com)
Date: Thu, 27 Sep 2007

"Steve Mitchel" <ste…@eventpro.net> wrote in message
news:21ADF6B61A37E340ste…@eventpro.net...

> Instead the line where I run my HttpConnection.Post raises
> an exception with the following error: "HTTP/1.1 400 Bad Request".

Then you are not uploading the data correctly.

> streamFormData.AddFile('comxmlfile', aFile, 'multipart/form-data');

That is not the correct ContentType value to use, and is likely what is
causing the server to fail.  You need to use the file's actual ContentType,
which for XML is 'text/xml', ie:

    streamFormData.AddFile('comxmlfile', aFile, 'text/xml');

Alternatively:

    streamFormData.AddFile('comxmlfile', aFile, GetMIMETypeFromFile(aFile));

'multipart/form-data' is the ContentType that Post() will apply to the
overall request for you.  It does not belong on any of the individual
fields.

> Result    := streamResponse.DataString;

Rather than using a TStringString manually, you can use Post()'s return
value instead:

    Result := HttpConnection.Post(TransferOptions.VenueCheck.Url,
streamFormData);

That would be one less stream that you have to manage yourself.

Gambit

Replies

In response to

HTTP/1.1 400 Bad Request posted by Steve Mitchel on Thu, 27 Sep 2007