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.

相关阅读 >>

Delphi xe5实现随机大小写字幕或者数字

Delphi 基础计算两数之合

Delphi关于延迟时间的一点智慧

Delphi 学习 sql 语句 - insert、update、delete

Delphi 中的文件系统进行unicode标准化

Delphi net.httpclient正则批量获取网页代码中的数值

Delphi10.3通过rest单元使类和json数据互相转换

Delphi tfilestream流操作1

阻止删除文件(文件占坑)的Delphi代码

Delphi datamodule1 fdconnection1数据库连接

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



打赏

取消

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

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

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

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

评论

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