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.

相关阅读 >>

android开发-px和dip以及sp的区别

Delphi得到系统目录的几个方法

Delphi 禁止用户关闭操作系统

Delphi tstringlist的delimitedtext的空格问题

Delphi xe10 手机端错误提示:detected problems with api compatibility (visit g.co/dev/appcompat for more info

Delphi string.create(char,count)

Delphi获取程序所在目录

Delphi的rtti实现数据集的简单对象化

Delphi 键盘钩子的简单应用

Delphi tadoquery的用法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...