加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
uMain.pas 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
EZAge 提交于 2021-06-26 14:57 . D7源码
unit uMain;
interface
uses
StrUtils, HTTPClient,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IdBaseComponent, IdComponent, IdTCPServer,
IdCustomHTTPServer, IdHTTPServer;
type
TfrmMain = class(TForm)
mmoRev: TMemo;
btn1: TButton;
btn2: TButton;
btn3: TButton;
idhtpsrvr1: TIdHTTPServer;
procedure btn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure btn3Click(Sender: TObject);
procedure idhtpsrvr1CommandGet(AThread: TIdPeerThread;
ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo);
private
{ Private declarations }
FHTTPClient:THTTPClient;
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.FormCreate(Sender: TObject);
begin
FHTTPClient:=THTTPClient.Create;
idhtpsrvr1.Active:=True;
end;
procedure TfrmMain.btn1Click(Sender: TObject);
var
url,data:string;
header:TStringList;
begin
url:='http://localhost:8998/test';
data:='{"test":"12345"}';
header:=TStringList.Create;
header.Values[HTTP_CONTENT_TYPE]:='application/json';
header.Values[HTTP_ACCEPT]:='application/json';
header.Values[HTTP_CHARSET]:='UTF-8';
mmoRev.Text:=Utf8ToAnsi(HttpPost(url,data,header.Text));
header.Free;
end;
procedure TfrmMain.btn3Click(Sender: TObject);
begin
mmoRev.Text:=Utf8ToAnsi(HttpGet('http://localhost:8998/test'));
end;
procedure TfrmMain.btn2Click(Sender: TObject);
var
url,sFile:string;
begin
url:='https://www.baidu.com/img/flexible/logo/pc/result.png';
sFile:='.\logo.png';
if HttpDownLoad(url,sFile) then
mmoRev.Text:=sFile
else
mmoRev.Text:='ʧ';
end;
procedure TfrmMain.idhtpsrvr1CommandGet(AThread: TIdPeerThread;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
AResponseInfo.ContentText:=ARequestInfo.RawHTTPCommand+#13#10+ARequestInfo.FormParams;
AResponseInfo.CloseSession;
end;
end.
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化