Delphi中idHttpServer
Delphi7中测试idHttpServer,自带的idHttpServer
仅放上测试的部分代码,便于自己查看
1 unit Unit1;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs
7 , IdBaseComponent, IdComponent, IdTCPServer, IdCustomHTTPServer, IdHTTPServer
8 , IdThreadMgr, IdThreadMgrPool, StdCtrls, IniFiles, DB, ADODB, WinSock
9 ;
10
11 type
12 TForm1 = class(TForm)
13 IdHTTPServer1: TIdHTTPServer;
14 IdThreadMgrPool1: TIdThreadMgrPool;
15 Label1: TLabel;
16 ADOQuery1: TADOQuery;
17 ADOConnection1: TADOConnection;
18 Button1: TButton;
19 procedure FormCreate(Sender: TObject);
20 procedure IdHTTPServer1CommandGet(AThread: TIdPeerThread; ARequestInfo: TIdHTTPRequestInfo
21 ; AResponseInfo: TIdHTTPResponseInfo);
22 procedure Button1Click(Sender: TObject);
23 procedure FormDestroy(Sender: TObject);
24 private
25 procedure sqlexec(vs1,vs2:string);
26 { Private declarations }
27 public
28 { Public declarations }
29 end;
30
31 var
32 Form1: TForm1;
33
34 implementation
35
36 {$R *.dfm}
37
38 //uses untDM;
39 function GetSysComputerIP: string;
40 var
41 vHostName: array[0..255] of Char;
42 vWSData: TWSAData;
43 vHost: PHostEnt;
44 begin
45 Result := '127.0.0.1';
46 WSAstartup(2, vWSData);
47 GetHostName(@vHostName[0], SizeOf(vHostName));
48 vHost :=GetHostByName(@vHostName[0]);
49 if vHost <> nil then
50 Result :=Format('%d.%d.%d.%d', [Ord(vHost.h_addr^[0]), Ord(vHost.h_addr^[1]), Ord(vHost.h_addr^[2]), Ord(vHost.h_addr^[3])]);
51 WSACleanup;
52 end;
53
54 procedure TForm1.FormCreate(Sender: TObject);
55 var
56 ini: TIniFile;
57 begin
58 IdHTTPServer1.ThreadMgr := IdThreadMgrPool1;
59 //设置绑定参数
60 IdHTTPServer1.Active := False;
61 IdHTTPServer1.Bindings.Clear;
62 ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'config.ini');
63 try
64 IdHTTPServer1.DefaultPort := ini.ReadInteger('local', 'port', 0);
65 finally
66 ini.Free;
67 end;
68 IdHTTPServer1.Bindings.Add.IP :=GetSysComputerIP;
69 //启动服务器
70 IdHTTPServer1.Active := True;
71 ADOConnection1.Connected:=True;
72 end;
73
74 procedure TForm1.IdHTTPServer1CommandGet(AThread: TIdPeerThread; ARequestInfo: TIdHTTPRequestInfo;
75 AResponseInfo: TIdHTTPResponseInfo);
76 var
77 method, vt1,vT2: string;
78 s:string;
79 // v:TStringStream;
80 ContentStream1 : TStream;
81 i:Integer;
82 begin
83 method := ARequestInfo.Document;
84
85 ShowMessage(Utf8ToAnsi(ARequestInfo.FormParams));
86
87 //ShowMessage( ARequestInfo.RawHTTPCommand);
88 if method = '/Api/test' then
89 begin
90 vt1 := ARequestInfo.Params.Values['t1'];
91 vt2 := ARequestInfo.Params.Values['t2'];
92 AResponseInfo.ResponseNo := 0;
93 AResponseInfo.ContentType := 'text/html';
94
95 try
96 sqlexec(vt1,vt2);
97 AResponseInfo.ContentText :=vt1+vt2;
98 AResponseInfo.WriteContent;
99 finally
100
101 end;
102 end;
103 end;
104
105 procedure TForm1.sqlexec(vs1, vs2: string);
106 begin
107 ADOQuery1.Close;
108 ADOQuery1.SQL.Text:=Format('insert into dbo.table2(D,E) values(''%s'',''%s'')',[vs1,vs2]);
109 ADOQuery1.ExecSQL;
110 end;
111
112 procedure TForm1.Button1Click(Sender: TObject);
113 begin
114 ShowMessage(GetSysComputerIP);
115 end;
116
117 procedure TForm1.FormDestroy(Sender: TObject);
118 begin
119 IdHTTPServer1.Active := False;
120 ADOConnection1.Connected:=False;
121 end;
122
123 end.
---------------------------
网页Post的总不知道怎么获取参数
以下资料来源:https://blog.csdn.net/weixin_33924770/article/details/86399065
1 procedure TFrmMain.HTTPServerCommandGet(AThread: TIdPeerThread;
2 ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
3 var
4 RespStr,recvText: string;
5 msgText: string;
6 begin
7 CoInitialize(nil);
8 try
9 try
10 msgText := 'Log|【'+FormatDateTime('yyyy-mm-dd hh:mm:ss',Now)+'】'+Format('收到请求:类型:%s, 路径:%s,来自:%s:%d',
11 [ARequestInfo.Command, ARequestInfo.Document,
12 TIdIOHandlerSocket(AThread.Connection.IOHandler).Binding.PeerIP,
13 TIdIOHandlerSocket(AThread.Connection.IOHandler).Binding.PeerPort]);
14
15 SendMessage(FrmMain.Handle,MYTHREAD_MESSAGE,Integer(@msgText),1);
16 if ARequestInfo.Command = 'GET' then
17 recvText := Utf8ToAnsi(Httpdecode(ARequestInfo.QueryParams)) //引用 Httpapp
18 else if ARequestInfo.Command = 'POST' then//post
19 recvText := Utf8ToAnsi(ARequestInfo.FormParams);
20 if (Pos(LowerCase('/api/getBusinessHallStatus'), LowerCase(ARequestInfo.Document)) = 1) then //查询营业厅状态接口
21 begin
22 RespStr := Httpserver_getBusinessHallStatus(recvText);
23 end
24 begin
25 RespStr := 'URL路径未定义';
26 end;
27 AResponseInfo.ContentType := 'text/HTML;charset=utf-8';
28 AResponseInfo.ContentText := AnsiToUtf8(RespStr);except
29 on e: Exception do
30 begin
31 msgText := 'ErrorLog|【'+FormatDateTime('yyyy-mm-dd hh:mm:ss',Now)+'】执行HTTPServerCommandGet发生异常,原因::'+e.Message;
32 SendMessage(FrmMain.Handle,MYTHREAD_MESSAGE,Integer(@msgText),1);
33 end;
34 end;
35 finally
36 CoUninitialize;
37 end;
38 end;
-----------------------------------
只是测试
Delphi中idHttpServer的更多相关文章
- delphi中的idhttpserver如何才能收到idhttp发送来的exe\rar文件呢
http://zhidao.baidu.com/link?url=-q2oXqYCKBZ9OgFDEHAcQwQEY_NroHcqGvVfKW67X5sF9LdjAAB_HPXQo04VxStFVS7 ...
- Delphi中stringlist分割字符串的用法
Delphi中stringlist分割字符串的用法 TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. 常规的用法大家都知道,现在来讨论它的一些高级的用法. 1.CommaT ...
- delphi中exit,abort,break,continue 的区别
from:http://www.cnblogs.com/taofengli288/archive/2011/09/05/2167553.html delphi中表示跳出的有break,continue ...
- Delphi中使用比较少的一些语法
本文是为了加强记忆而写,这里写的大多数内容都是在编程的日常工作中使用频率不高的东西,但是又十分重要. ---Murphy 1,构造和析构函数: a,构造函数: 一般基于TComponent组件的派生类 ...
- 如何在 Delphi 中静态链接 SQLite
搞了我几个小时,终于成功在 Delphi 中静态链接了 SQLite (v3.5.4),下一步就是研究加密了,呵呵中间其实遇到很多问题,今天累了,就不说了,改天补上 下载测试工程 下面说说方法 1.当 ...
- 翻箱倒柜,《Delphi中建议使用的语句》
(*//标题:Delphi中建议使用的语句整理:Zswang连接:http://www.csdn.net/Expert/TopicView1.asp?id=724036日期:2002-06-22支持: ...
- delphi中break,continue, exit,abort, halt, runerror的异同
delphi中表示跳出的有break,continue, exit,abort, halt, runerror. 1.break 强制退出循环(只能放在循环中),用于从For语句,while语句或re ...
- delphi中midas是什么
Delphi中MIDAS到底是什么呢?和他相关组件是什么呢? MIDAS(Multitiered Distributed Application Services)多层分布式应用服务. Del ...
- Delphi中window消息截获的实现方式(2)
Delphi是Borland公司提供的一种全新的WINDOWS编程开发工具.由于它采用了具有弹性的和可重用的面向对象Pascal(object-orientedpascal)语言,并有强大的数据库引擎 ...
- Delphi 中的 procedure of object
转载:http://www.cnblogs.com/ywangzi/archive/2012/08/28/2659811.html 总结:TMyEvent = procedure of object; ...
随机推荐
- ICPC2020 沈阳
F-Kobolds and Catacombs 牛客网 题意:对于\(n(n<=10^6)\)个数的序列,划分区间,每个区间内部从小到大排序,要求最后整个序列单调不下降,求最多可以划分为多少个区 ...
- Chrome 中的 JavaScript 断点设置和调试技巧--转自hanguokai.com
你是怎么调试 JavaScript 程序的?最原始的方法是用 alert() 在页面上打印内容,稍微改进一点的方法是用 console.log() 在 JavaScript 控制台上输出内容.嗯~,用 ...
- Supervisor安装及配置
Supervisor安装 # 安装 easy_install supervisor # 生成默认配置文件 echo_supervisord_conf > /etc/supervisord.con ...
- 删除File Explorer、This PC、Folders
win+R,输入regedit,打开Registry Editor 定位:Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentV ...
- C++实现顺序表相关操作
//顺序表#include<iostream>#include<cstdlib>//C中stdlib.h动态分配内存using namespace std;#define OK ...
- python sorted() 多重排序
前言: 最开始是因为看到一道题目, 用一行代码解决[1, 2, 3, 11, 2, 5, 3, 2, 5, 3] 输出[11, 1, 2, 3, 5] 本来想法很简单,先去重后排序 但是遇到一个难点 ...
- React脚手架的使用
初始化项目 npx create-react-app my-app // 或 npm init react-app my-app // 或 yarn create react-app my-app 启 ...
- vue中key
使用key维护列表的状态 当列表的数据变化时,默认情况下,vue尽可能的服用已存在的DOM元素,从而提升渲染的性能.但这种默认的性能优化策略,会导致由状态的列表无法被正确更新. key的使用注意事项: ...
- 每日一抄 Go语言等待组
package main import ( "fmt" "net/http" "sync" ) /* Go语言除了可以使用通道(channe ...
- Codeforces Round #728 (Div. 2) C. Great Graphs
Great Graphs 题意 给你一个数组\(d\),\(d[i]\)表示从节点\(1\)到其他各个节点的最短路的长度,然后你可以对这个图进行加边(可以是负边),但不允许存在一个权值和为负数的回路. ...