unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, CnMD5,
CnBase64,WinINet,IDURI,Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure Post(url, data, Len, Auth: string; res: TStream);
var
hInt, hConn, hreq: HINTERNET;
buffer: PChar;
dwRead, dwFlags: cardinal;
port: Word;
uri: TIdURI;
proto, host, path: string;
header:string;
begin
uri := TIdURI.Create(url);
host := uri.Host;
path := uri.Path + uri.Document + uri.Params;
proto := uri.Protocol;
uri.Free;
if UpperCase(proto) = 'HTTPS' then
begin
port := INTERNET_DEFAULT_HTTPS_PORT;
dwFlags := INTERNET_FLAG_SECURE;
end
else
begin
port := INTERNET_INVALID_PORT_NUMBER;
dwFlags := INTERNET_FLAG_RELOAD;
end;
hInt := InternetOpen('Delphi', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
hConn := InternetConnect(hInt, PChar(host), 8883, nil, nil, INTERNET_SERVICE_HTTP, 0, 0);
hreq := HttpOpenRequest(hConn, 'POST', PChar(Path), 'HTTP/1.1', nil, nil, dwFlags, 0);
GetMem(buffer, 65536);
header:='Content-Length:'+len+
#13'Accept:application/json'+
#13'Content-Type:application/json'+
#13'Authorization:'+auth;
if HttpSendRequest(hReq, PAnsiChar(header), Length(header), PChar(data), Length(data)) then
begin
dwRead := 0;
repeat
InternetReadFile(hreq, buffer, 65536, dwRead);
if dwRead <> 0 then
res.Write(buffer^, dwRead);
until dwRead = 0;
end;
InternetCloseHandle(hreq);
InternetCloseHandle(hConn);
InternetCloseHandle(hInt);
FreeMem(buffer);
end;
procedure TForm2.Button1Click(Sender: TObject);
var
s: string;
sig: string;
b64: string;
t: string;
l,content: string;
Responses: TStringStream;
begin
t := formatdatetime('yyyyMMddHHnnss', Now);
sig := UpperCase(MD5Print(MD5String('123123123' + '234234234234' + t)));
Base64Encode('2221232321:' + t, b64);
content:=AnsiToUtf8('{"from":"13155555555","to":"18822225555"}');
l := IntToStr(Length(content));
Responses := TStringStream.Create('');
s := 'https://www.good.com:856/Callback?sig=' + sig + '';
Post(s, content,l,b64, Responses);
Memo1.text := Utf8ToAnsi(Responses.DataString);
Responses.Free;
end;
end.

zflybird
- 粉丝: 12
最新资源
- 新时代高职生网络生活状况研究.docx
- 基于改进粒子群优化算法的 BP 神经网络房价预测研究
- 人工智能写作会不会抢了电竞媒体的饭碗?.docx
- 单片机与PC机的温控制系统硬件设计.doc
- 基于51单片机ds1302和ds18b20芯片方案设计书的电子日历.doc
- ASPnet管理开题.doc
- 电子商务专业个人简历-范例.doc
- 2015最新Excel甘特图模板项目管理必备.xls
- 单片机测控系统中的抗干扰技术.doc
- (源码)基于C++的Alexa Voice Service原型.zip
- 基于单片机的水箱温自动控制系统设计张强.doc
- Go编程语言全面指南
- 大数据-资本市场下一波的宠儿.docx
- 谈供电局配网自动化的研究与实现.docx
- 基于词典与机器学习的中文微博情感分析.docx
- 基因工程制药下游技术生物学自然科学专业资料.ppt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



- 1
- 2
- 3
- 4
- 5
- 6
前往页