TWinHttp之二
TWinHttp之二
function EncodeParams(strings: TStrings): SockString;
var
i: Integer;
S: string;
begin
for i := 0 to strings.Count - 1 do
begin
S := strings.Names[i];
if Length(strings.Values[S]) > 0 then
begin
strings.Values[S] := UrlEncode(strings.Values[S]);
end;
if Result = '' then
Result := strings[i]
else
Result := Result + '&' + strings[i];
end;
end;
function httppost(const url, password: SockString; params: TStrings; var ResponseData: SockString): Integer;
var
aURI: TURI;
http: TWinHTTP;
head: SockString;
begin
http := nil;
try
aURI.From(url);
http := TWinHTTP.Create(aURI.Server, aURI.Port, aURI.Https);
http.AuthUserName := 'cxg';
http.AuthPassword := '929';
http.IgnoreSSLCertificateErrors := true;
Result := http.Request(aURI.Address, 'POST', 0, '', EncodeParams(params), password, head, ResponseData);
finally
aURI.Clear;
http.Free;
end;
end;
function httpget(const fullurl, password: SockString; var ResponseData: SockString): Integer;
var
aURI: TURI;
http: TWinHTTP;
head: SockString;
begin
http := nil;
try
aURI.From(fullurl);
http := TWinHTTP.Create(aURI.Server, aURI.Port, aURI.Https);
http.IgnoreSSLCertificateErrors := true;
Result := http.Request(aURI.Address, 'GET', 0, '', '', password, head, ResponseData);
finally
aURI.Clear;
http.Free;
end;
end;
procedure getQry(const url, sql: string; var data: SockString);
var
aurl: string;
begin
aurl := url + 'query?sql=' + UrlEncode(sql);
if httpget(aurl, 'yn', data) = 404 then
begin
ShowMessage('登陆中间件验证失败');
Abort;
end;
end;
procedure postQry(const url, sql: string; var data: SockString);
var
aurl: string;
params: TStrings;
begin
params := TStringList.Create;
try
params.Add('sql=' + sql);
aurl := url + 'query';
if httppost(aurl, 'yn', params, data) = 333 then
begin
ShowMessage('登陆中间件验证失败');
Abort;
end;
finally
params.Free;
end;
end;
procedure postExecute(const url, sql: string; var data: SockString);
var
aurl: string;
params: TStrings;
begin
params := TStringList.Create;
try
params.Add('sql=' + sql);
aurl := url + 'execute';
if httppost(aurl, 'yn', params, data) = 333 then
begin
ShowMessage('登陆中间件验证失败');
Abort;
end;
finally
params.Free;
end;
end;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/8056510.html