unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,idMultipartformdata,MsMultiPartFormData, IdBaseComponent, IdComponent,
IdTCPServer, IdCustomHTTPServer, IdHTTPServer, IdTCPConnection,
IdTCPClient, IdHTTP;
type
TForm1 =
class(TForm)
Button1: TButton;
httpMain: TIdHTTP;
Button2: TButton;
Memo1: TMemo;
Button3: TButton;
IdHTTP1: TIdHTTP;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Stream: TMSMultiPartFormDataStream;
StringStream: TStringStream;
begin
Stream := TMSMultiPartFormDataStream.Create;
StringStream := TStringStream.Create('
');
try
Stream.AddFormField('
upload', '
');
Stream.AddFormField('
MAX_FILE_SIZE', '
10485760');
Stream.AddFormField('
upload_von','
computer');
Stream.AddFile('
datei', '
C:\bild.jpg', '
image/jpeg');
IdHTTP1.Request.ContentType := '
application/x-www-form-urlencoded';
IdHTTP1.Post('
http://picupload.org/index.php', Stream, StringStream);
memo1.text:=idhttp1.ResponseText;
finally
Stream.Free;
//StringStream.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
DataStream: TidMultiPartFormDataStream;
Response:
string;
begin
DataStream:=TidMultiPartFormDataStream.Create;
try
IdHTTP1.Request.ContentType:='
multipart/form-data';
DataStream.AddFormField('
upload', '
');
DataStream.AddFormField('
MAX_FILE_SIZE', '
10485760');
DataStream.AddFormField('
upload_von','
computer');
DataStream.AddFile('
file','
C:\bild.jpg','
image/jpg');
//Response:=IdHTTP1.Post('http://picupload.org',DataStream);
memo1.Text:=IdHTTP1.Post('
http://picupload.org/index.php',DataStream);
finally
DataStream.Free;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
MultiPartFormDataStream: TMsMultiPartFormDataStream;
HttpServer, Response:
String;
begin
// Objekte instanzieren
MultiPartFormDataStream := TMsMultiPartFormDataStream.Create;
try
// Content-Type bestimmen
httpMain.Request.ContentType := MultiPartFormDataStream.RequestContentType;
// andere Formular-Felder übergeben
MultiPartFormDataStream.AddFormField('
upload','
1');
MultiPartFormDataStream.AddFormField('
MAX_FILE_SIZE','
10485760');
MultiPartFormDataStream.AddFormField('
upload_von','
computer');
// Datei laden
MultiPartFormDataStream.AddFile('
file','
C:\bild.jpg','
image/jpeg');
// Anfrage vorbereiten
MultiPartFormDataStream.PrepareStreamForDispatch;
{ You must make sure you call this method *before* sending the stream }
MultiPartFormDataStream.Position := 0;
try
// Anfrage stellen
//Response := httpMain.Post('http://picupload.org/index.php', MultiPartFormDataStream);
//memo1.Text:=Response;
memo1.Text:= httpMain.Post('
http://picupload.org/index.php', MultiPartFormDataStream);
except
//Upload fehlgeschlagen
end;
//end;
finally
MultiPartFormDataStream.Free;
end;
end;
end.