Delphi : the request was rejected because no multipart boundary was found

Hello,

I use Delphi 2010 and I need to upload an xml file to a server.

I got the following instructions:
you should use HTTP POST request (type: multipart/form-data) and the
"stockdata" field should contain the  xml file

So I did this:

  try
    resStream := TMemoryStream.Create;
    try
      lParamList := TStringList.Create;
      try



         XML_File := TStringList.Create;
         XML_File.LoadFromFile(ExtractFilePath(ParamStr(0))+'Xml'+'\server_data.xml');

         lParamList.Add('stockdata=' +XML_File.Text );
       

        lHTTP := TIdHTTP.Create;
        try
          sshSocketHandler := TIdSSLIOHandlerSocketOpenSSL.Create(lHTTP);
          lHTTP.IOHandler := sshSocketHandler;

         postData := TIdMultiPartFormDataStream.Create;



         lHTTP.Request.ContentType := 'multipart/form-data';

         lHTTP.Post('http://xml.serveraddress', lParamList, resStream);
        finally
          lHTTP.Free;
        end;
      finally
        lParamList.Free;
      end;
      resStream.Position := 0;

      MemoMessage.Lines.LoadFromStream(resStream);

    finally
      resStream.Free;
    end;
  except
    on E: Exception do
    begin

      ShowMessage(E.Message);
    end;
  end;

Open in new window


The server answer is all the time:
org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found

Thank you
starhuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sinisa VukSoftware architectCommented:
Try to set:
lHTTP.Request.ContentType := 'text/xml';

Open in new window

0
starhuAuthor Commented:
lHTTP.Request.ContentType := 'text/xml';
                                           

In this case the server doesn't give back anything and it doesn't do anything either.

I noticed that if the ContentType  is not 'multipart/form-data', it doesn't do anything.

e.g. if lHTTP.Request.ContentType :='Content-Type: multipart/form-data' then too it gives back empty string.

Normally it would give back how many products it uploaded.

This is a tiny software. Would it be easier if I sent the software code in private?

Thank you
0
Sinisa VukSoftware architectCommented:
You sand text which must be body of multipart... For your case you need to build envelope to suits this ...(TIdMultipartFormDataStream)
http://stackoverflow.com/questions/10765661/http-post-with-indy
http://www.rsdn.ru/forum/delphi/4221607.hot (last post)

without TIdMultipartFormDataStream:
http://delphi-kb.blogspot.com/2011/06/using-indy-idhttp-to-post-binary-and_3736.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.