unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls; type
TForm1 = class(TForm)
btn1: TButton;
IdHTTP1: TIdHTTP;
procedure btn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.btn1Click(Sender: TObject);
var
iLen:integer;
sFN,sPath:string;
MS,MS2:TMemoryStream;
begin
MS:=TMemoryStream.Create;
try
sPath:=ExtractFilePath(application.ExeName)+'a.bmp';
sFN:=ExtractFileName(sPath);
iLen:=length(sFN); MS.WriteBuffer(iLen,sizeof(iLen));
MS.WriteBuffer(sFN[],iLen); MS2:=TMemoryStream.Create;
MS2.LoadFromFile(sPath); iLen:=MS2.Size; MS.WriteBuffer(iLen,sizeof(iLen)); MS.CopyFrom(MS2,iLen);
MS2.Free;
IDHTTP1.post('http://127.0.0.1:2111',MS,nil);
finally
MS.Free;
end;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
// IdHTTP1.Host:= '127.0.0.1';
// IdHTTP1.Port:= 2111;
end; end. unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPServer, IdCustomHTTPServer,
IdHTTPServer; type
TForm1 = class(TForm)
IdHTTPServer1: TIdHTTPServer;
procedure IdHTTPServer1CommandGet(AThread: TIdPeerThread;
ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.IdHTTPServer1CommandGet(AThread: TIdPeerThread;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
iLen:Integer;
sData,sFN:string;
MS:TMemoryStream;
pData:PChar;
begin
sData:=ARequestInfo.UnparsedParams;
if sData<>'' then
begin
{
自己定义一个简单的消息格式,数据长度1,数据1,数据长度2,数据2 |文件名长度|文件名|文件内容长度|文件内容|
|5|a.bmp|17788|0x10101010101001010100101...| } MS:=TMemoryStream.Create;
try
//1读取文件名
MS.WriteBuffer(sData[],length(sData));
MS.Position:=;
MS.ReadBuffer(iLen,sizeof(iLen)); //读文件名长度
SetLength(sFN,iLen);
MS.ReadBuffer(sFN[],iLen); //读文件名
//2读取文件内容
MS.ReadBuffer(iLen,sizeof(iLen));//读文件内容长度
GetMem(pData,iLen);
MS.ReadBuffer(pData^,iLen);//读文件内容 pData里面保存的就是图片数据 //3保存为文件
MS.Clear;
MS.WriteBuffer(pData^,iLen);
MS.SaveToFile(ExtractFilePath(Application.ExeName) +sFN);
finally
MS.Free;
end;
end;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
IdHTTPServer1.DefaultPort:= ;
IdHTTPServer1.Active:= true;
Self.Caption:= '启动';
end; end.

最新文章

  1. SqlServer性能优化(一)
  2. Android UI 绘制过程浅析(三)layout过程
  3. mac上抓iphone数据包
  4. [Xamarin] 透過 intent-filter 來接管 http ,製作偽瀏覽器 (转帖)
  5. Thinkphp中验证码的使用以及验证的实现
  6. yii2构造方法
  7. flappy pig小游戏源码分析(1)——主程序初探
  8. 嵌入式linux平台搭建
  9. [C#][转]与MySql连接访问
  10. Matlab与.NET基于类型安全的接口混合编程入门
  11. Linux svn服务的搭建
  12. POI tools 参数化生成excel表格
  13. c++模板使用及实现模板声明定义的分离
  14. HTML中的坐标系及其在MouseEvent和元素Box中的应用
  15. Python学习日记 --day3
  16. 从零开始学 Spring Boot
  17. ASP.NET Core StaticFiles中间件修改wwwroot(转载)
  18. PAT甲级题解-1123. Is It a Complete AVL Tree (30)-AVL树+满二叉树
  19. Django 之单个mysql表使用
  20. python小数据池概念以及具体范围

热门文章

  1. maven-本地安装jar包
  2. laravel.url
  3. 刷题23. Merge k Sorted Lists
  4. 这26个为什么,让初学者理解Python更简单!
  5. java核心-JVM-gc面试题
  6. 058-PHP中goto语句的使用
  7. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-share
  8. 尝试用kotlin做一个app(五)
  9. 【题解】Acting Cute
  10. CodeForces - 402B Trees in a Row (暴力)