delphi idHttp上传图给ASP完美解决

//很早前,也有2、3年前了,使用过这个类 IdMultiPartFormData 突然想起了,当时初学delphi要上传图像,花了几天时间在网上找资料。如今我怕忘记了,转载这篇文章:

全文:http://blog.sina.com.cn/s/blog_6b6e6bad0100yvwx.html

 

delphi idHttp上传图给ASP完美解决

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls,IdMultiPartFormData;

type
TForm1 = class(TForm)
Button1: TButton;
IdHTTP1: TIdHTTP;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
res : String;
ms : TIdMultiPartFormDataStream;
h: TIdhttp;
f:string;
begin
if Opendialog1.Execute then
f:=Opendialog1.FileName;
if f='' then exit;
try
ms := TIdMultiPartFormDataStream.Create;
h := Tidhttp.Create(nil);
ms.AddFile('file1',f,'');
idhttp1.Request.ContentType := 'multipart/form-data' ;
res:=h.Post('http://www.oro.com/Admin/u.asp?menu=up',ms);
if res='上传成功' then
Application.MessageBox('图片上传成功!','提示',MB_OK+MB_ICONASTERISK)
else
Application.MessageBox('图片上传失败!','ERROR',MB_OK+MB_ICONSTOP);
finally
ms.Free;
end;
end;


end.

posted @ 2016-03-08 22:38  stma  阅读(967)  评论(0)    收藏  举报