Simulate IE to upload a file to IIS

Giganews Newsgroups
Subject: Simulate IE to upload a file to IIS
Posted by:  Lars Sondergaard (x…@nomail.com)
Date: Wed, 5 Jan 2005

Hi

If I use IE to go to a web page with code as listed below I can select a
file from my disk and upload it to the IIS server. On the server I can
specify a location where the file will be placed.

My question/problem is how I can upload a file to this page using Indy
components.

I have tried using the following code:

var
  FormData: TIdMultiPartFormDataStream;
  idHTTP: TidHTTP;
begin
  FormData:=TIdMultiPartFormDataStream.Create;
  FormData.AddFormField('FULLNAME','MyName');
  FormData.AddFile('FILE1','C:\testfile.dat','');
  idHTTP:=TidHTTP.Create(nil);
  idHTTP.Post(WebPageURL,FormData);
  FormData.Free;
  idHttp.Free;
end;

(I am using Indy version 9.0.15)

I get an error "HTTP/1.1 405 Method not allowed  ()" when I try to run this
code.

Here is the code for the web page

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<FORM METHOD="POST" ENCTYPE="multipart/form-data"
ACTION="uploadhandler.asp">
<TABLE BORDER=0>
<tr><td><b>Enter your fullname:</b><br><INPUT TYPE=TEXT SIZE=40
NAME="FULLNAME"></td></tr>
<tr><td><b>Select a file to upload:</b><br><INPUT TYPE=FILE SIZE=50
NAME="FILE1"></td></tr>
<tr><td align="center"><INPUT TYPE=SUBMIT VALUE="Upload!"></td></tr>
</TABLE>
</FORM>
</BODY>
</HTML>

Any help would be much appreciated

Lars

Replies