Delphi 德尔菲。WinInet+;思科+;NTLM。12045和12057错误
我通过Cisco连接到公司网络,然后通过域NTLM授权连接到公司https站点 所以我通过代理(只要在IE中用密码登录就足够了),程序就会进入除公司网站以外的所有网站,失败时出现错误12045(错误为INTERNET\u无效\u CA)或12057 如何从商店获得证书?当然,不需要使用带有密码和证书名的用户名。 救命啊,谁知道呢。我也通过http进行了尝试 以下是函数:Delphi 德尔菲。WinInet+;思科+;NTLM。12045和12057错误,delphi,winapi,ntlm,wininet,internetsetoption,Delphi,Winapi,Ntlm,Wininet,Internetsetoption,我通过Cisco连接到公司网络,然后通过域NTLM授权连接到公司https站点 所以我通过代理(只要在IE中用密码登录就足够了),程序就会进入除公司网站以外的所有网站,失败时出现错误12045(错误为INTERNET\u无效\u CA)或12057 如何从商店获得证书?当然,不需要使用带有密码和证书名的用户名。 救命啊,谁知道呢。我也通过http进行了尝试 以下是函数: 函数wininetrest(AUrl、AParam、AMethod、AType_Access:String;APostData
函数wininetrest(AUrl、AParam、AMethod、AType_Access:String;APostData:boolean):AnsiString;
函数GetHostName(AUrl:string):string;
变量
s:字符串;
开始//主机名
如果Pos('https://',AUrl)>0,则
s:=“https://”
其他的
如果Pos('http://',AUrl)>0,则
s:=“http://”
其他的
s:=EmptyStr;
如果是空的话
如果位置(s,AUrl)>0,则
删除(AUrl,1,长度);
如果Pos('/',AUrl)>0,则
设置长度(AUrl,Pos('/',AUrl)-1);
结果:=AUrl;
结束;
函数GetScriptName(AUrl,AHostname:string):string;
开始
结果:=EmptyStr;
删除(AUrl,1,Pos(AHostname,AUrl)+长度(AHostname));
结果:=AUrl;
结束;
过程SetFlags(AUrl:string;out-Flags\u-connection,Flags\u-Request:Cardinal);
开始//选择http或https
如果Pos('https',AUrl)>0,则
开始
标志\u连接:=互联网\u默认\u HTTPS\u端口;
标志\u请求:=互联网标志\u重新加载
或INTERNET标志\u忽略\u证书\u CN\u无效
或互联网\u标志\u忽略\u证书\u日期\u无效
或安全\u标志\u忽略\u未知\u CA
或互联网\u标志\u无\u缓存\u写入
或互联网标志安全
或互联网标志、布拉格语、NOCACHE
或互联网标志保持连接;
结束其他
开始
标志\u连接:=互联网\u默认\u HTTP\u端口;
标志请求:=互联网标志重新加载或互联网标志忽略证书CN无效或互联网标志无缓存写入或互联网标志无缓存或互联网标志保持连接;
结束;
结束;
变量
hInet、hCon、hReq:HINTERNET;
状态、索引、dwErrorCode、状态大小:DWORD;
字节,b,位置:基数;
主机名,脚本:string;
Flags\u连接、Flags\u请求:基数;
ISSEND:布尔型;
标签
再一次;
开始
结果:=排空系统;
主机名:=GetHostName(AUrl);//主机名
脚本:=GetScriptName(AUrl,主机名);//剧本
// установка доп. параметров
如果不是数据,则//如果通过URL传递参数
如果是AParam EmptyStr,则//然后添加到脚本
如果脚本[长度(脚本)]=“?”则
脚本:=脚本+内存
其他的
脚本:=script+'?'+AParam;
//类型访问
如果AType_Access=EmptyStr,则
AType#U Access:=“内容类型:应用程序/x-www-form-urlenDELPHId”+#13#10+
'内容长度:'+IntToStr(长度(AParam));
尝试
//设置标志(httpццццhttps)
设置标志(AUrl、标志连接、标志请求);
//WinInet初始化
hInet:=互联网开放(PChar(Application.ExeName),互联网开放类型预配置,无,无,0)//
如果分配(hInet),则
尝试
//公开会议
hCon:=InternetConnect(hInet,PChar(主机名),标志连接,nil,nil,INTERNET服务\uHTTP,0,1);
如果已分配(hCon),则
尝试
//公开请求
hReq:=HttpOpenRequest(hCon,PChar(大写(AMethod)),PChar(脚本),HTTP_版本,nil,nil,Flags_请求,1);
如果分配(hReq),则
尝试//发送请求
个案资料
False:issend:=HttpSendRequest(hReq,nil,0,nil,0);
True:IsSend:=HttpSendRequest(hReq、PChar(AType_访问)、长度(AType_访问)、PChar(AParam)、长度(AParam));
结束;
如果未发送,则//证书错误
开始
//自动化窗口
{InternetErrorDlg(Application.Handle,
hReq,
错误\u互联网\u无效\u CA,
标记\u错误\u用户界面\u过滤器\u查找\u错误
或标志\u错误\u用户界面\u标志\u生成\u数据
或标志\u错误\u用户界面\u标志\u更改\u选项,
hReq);}
dwErrorCode:=GetLastError;
如果(dwErrorCode=12045),则
开始
ShowMessage('cert error!');
状态:=INTERNET\u标志\u安全
或INTERNET标志\u忽略\u证书\u CN\u无效
或互联网\u标志\u忽略\u证书\u日期\u无效
或安全标志忽略撤销;
StatusSize:=SizeOf(状态);
InternetQueryOption(hReq、INTERNET选项、安全标志、@Status、StatusSize);
状态:=状态或安全标志\u忽略\u未知\u CA;
InternetSetOption(hReq、INTERNET选项安全标志、@Status、SizeOf(Status));
个案资料
False:issend:=HttpSendRequest(hReq,nil,0,nil,0);
True:IsSend:=HTTPSendRequest(hReq、PChar(AType_访问)、长度(AType_访问)、PChar(AParam)、长度(AParam));
结束;
结束;
结束;
如果是这样的话
开始
StatusSize:=SizeOf(状态);
指数:=0;
HttpQueryInfo(hReq、HTTP_查询_状态_代码或HTTP_查询_标志_编号、@STATUS、StatusSize、Index);
如果状态HTTP\u Status\u正常,则
结果:=AnsiString('Кöааааааааааааа:'+IntToStr(状态)+sLineBreak+SYSERRORMES;
位置:=1;
b:=1;
当b>0时
开始
如果InternetQueryDataAvailable(hReq,字节,0,0)不可用,则
SECURITY_FLAG_IGNORE_UNKNOWN_CA
or SECURITY_FLAG_IGNORE_CERT_CN_INVALID
or SECURITY_FLAG_IGNORE_CERT_DATE_INVALID or
SECURITY_FLAG_IGNORE_REVOCATION
CONNECT site.ru:443 HTTP/1.0
User-Agent: C:\Dev\Testing.exe
Host: site.ru:443
Content-Length: 0
Connection: Keep-Alive
Pragma: no-cache
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 08:58:58.805
Connection: close
EndTime: 08:59:16.562
ClientToServerBytes: 1946
ServerToClientBytes: 6185
------------------------------------------------------------------
GET http://site.ru/cert/root.crt HTTP/1.1
Proxy-Connection: Keep-Alive
Accept: */*
User-Agent: Microsoft-CryptoAPI/10.0
Host: site.ru
HTTP/1.1 502 Fiddler - Connection Failed
Date: Mon, 27 Jan 2020 05:59:20 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Timestamp: 08:59:20.404
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:42:39.636
Connection: close
EndTime: 09:42:54.716
ClientToServerBytes: 205
ServerToClientBytes: 3183
------------------------------------------------------------------
GET http://site.ru/cert/root.crt HTTP/1.1
Proxy-Connection: Keep-Alive
Accept: */*
User-Agent: Microsoft-CryptoAPI/10.0
Host: site.ru
HTTP/1.1 502 Fiddler - Connection Failed
Date: Mon, 27 Jan 2020 06:43:00 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Timestamp: 09:43:00.722
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:42:54.747
Connection: close
EndTime: 09:42:54.785
ClientToServerBytes: 205
ServerToClientBytes: 3183
------------------------------------------------------------------ This site is not secure, I press "Go on to the webpage (not recommended)"
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:44:14.163
Connection: close
EndTime: 09:44:29.231
ClientToServerBytes: 205
ServerToClientBytes: 3183
------------------------------------------------------------------
GET http://site.ru/cert/root.crt HTTP/1.1
Proxy-Connection: Keep-Alive
Accept: */*
User-Agent: Microsoft-CryptoAPI/10.0
Host: site.ru
HTTP/1.1 502 Fiddler - Connection Failed
Date: Mon, 27 Jan 2020 06:44:35 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Timestamp: 09:44:35.225
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:44:29.294
Connection: close
EndTime: 09:44:29.362
ClientToServerBytes: 205
ServerToClientBytes: 3183
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:44:29.384
Connection: close
EndTime: 09:45:20.611
ClientToServerBytes: 36558
ServerToClientBytes: 168803
------------------------------------------------------------------ - entering password
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:10.675
Connection: close
EndTime: 09:45:20.620
ClientToServerBytes: 24661
ServerToClientBytes: 284264
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:10.674
Connection: close
EndTime: 09:45:20.628
ClientToServerBytes: 21760
ServerToClientBytes: 117787
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:10.674
Connection: close
EndTime: 09:45:12.743
ClientToServerBytes: 10519
ServerToClientBytes: 17470
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:10.674
Connection: close
EndTime: 09:45:14.875
ClientToServerBytes: 12684
ServerToClientBytes: 57032
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:10.673
Connection: close
EndTime: 09:45:27.157
ClientToServerBytes: 19947
ServerToClientBytes: 462607
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:10.673
Connection: close
EndTime: 09:45:12.729
ClientToServerBytes: 10348
ServerToClientBytes: 26830
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:10.668
Connection: close
EndTime: 09:45:29.979
ClientToServerBytes: 27178
ServerToClientBytes: 645488
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:10.673
Connection: close
EndTime: 09:45:14.866
ClientToServerBytes: 23141
ServerToClientBytes: 63723
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:10.673
Connection: close
EndTime: 09:45:29.563
ClientToServerBytes: 17702
ServerToClientBytes: 1107864
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:10.675
Connection: close
EndTime: 09:45:13.329
ClientToServerBytes: 5053
ServerToClientBytes: 43534
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:10.675
Connection: close
EndTime: 09:45:14.880
ClientToServerBytes: 19979
ServerToClientBytes: 91116
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:12.974
Connection: close
EndTime: 09:45:21.599
ClientToServerBytes: 15295
ServerToClientBytes: 198021
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:12.987
Connection: close
EndTime: 09:45:20.589
ClientToServerBytes: 21600
ServerToClientBytes: 221667
------------------------------------------------------------------
CONNECT piwik.mts.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: piwik.mts.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:13.368
Connection: close
EndTime: 09:45:28.443
ClientToServerBytes: 201
ServerToClientBytes: 2048
------------------------------------------------------------------
GET http://site.ru/cert/win.crt HTTP/1.1
Proxy-Connection: Keep-Alive
Accept: */*
User-Agent: Microsoft-CryptoAPI/10.0
Host: site.ru
HTTP/1.1 502 Fiddler - Connection Failed
Date: Mon, 27 Jan 2020 06:45:34 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Timestamp: 09:45:34.440
------------------------------------------------------------------
CONNECT site.ru:443 HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 0
Host: site.ru
Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic ****************
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:45:16.694
Connection: close
EndTime: 09:45:21.579
ClientToServerBytes: 20336
ServerToClientBytes: 179279
//If you don`t pass credentials (while creating object or after that) then request window will appear
unit UnitWinInet;
interface
uses
System.SysUtils, System.Types, WinInet, Winapi.Windows;
type
TWinInet = class
private
FHWND: THandle;
FClientName,
FParam,
FMethod,
FType_Access,
FLogin,
FPass: string;
FPostData: boolean;
procedure SetMethod(AMethod: string);
public
property HWND: THandle read FHWND write FHWND;
property ClientName: string read FClientName write FClientName;
property Param: string read FParam write FParam;
property Method: string read FMethod write SetMethod;
property Type_Access: string read FType_Access write FType_Access;
property Login: string read FLogin write FLogin;
property Pass: string read FPass write FPass;
property PostData: boolean read FPostData write FPostData;
function GetHTTP(AURL: string): AnsiString;
constructor Create(AHWND: THandle);
end;
implementation
constructor TWinInet.Create(AHWND: THandle);
begin
FHWND:= AHWND;
FClientName:= 'WinInet';
FMethod:= 'GET';
FType_Access:= 'Content-Type: application/x-www-form-urlenDELPHId' + #13#10 +
'Content-Length:' + IntToStr(length(FParam));
FPostData:= False;
end;
procedure TWinInet.SetMethod(AMethod: string);
begin
FMethod:= UpperCase(AMethod);
end;
function TWinInet.GetHTTP(AURL: string): AnsiString;
function GetHostName(AUrl: string): string;
var
s: string;
begin
if Pos('https://', AUrl) > 0 then
s:= 'https://'
else
if Pos('http://', AUrl) > 0 then
s:= 'http://'
else
s:= EmptyStr;
if s <> EmptyStr then
if Pos(s, AUrl) > 0 then
Delete(AUrl, 1, Length(s));
if Pos('/', AUrl) > 0 then
SetLength(AUrl, Pos('/', AUrl) - 1);
Result:= AUrl;
end;
function GetScriptName(AUrl, AHostname: string): string;
begin
Result:= EmptyStr;
Delete(AUrl, 1, Pos(AHostname, AUrl) + Length(AHostname));
Result:= AUrl;
end;
procedure SetFlags(AUrl: string; out Flags_connection, Flags_Request: Cardinal);
begin
if Pos('https', AUrl) > 0 then
begin
Flags_connection:= INTERNET_DEFAULT_HTTPS_PORT;
Flags_Request:= INTERNET_FLAG_RELOAD
or INTERNET_FLAG_NO_CACHE_WRITE
or INTERNET_FLAG_SECURE
or INTERNET_FLAG_IGNORE_CERT_CN_INVALID
or INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
or INTERNET_FLAG_KEEP_CONNECTION
end else
begin
Flags_connection:= INTERNET_DEFAULT_HTTP_PORT;
Flags_Request:= INTERNET_FLAG_RELOAD
or INTERNET_FLAG_IGNORE_CERT_CN_INVALID
or INTERNET_FLAG_NO_CACHE_WRITE
or INTERNET_FLAG_PRAGMA_NOCACHE
or INTERNET_FLAG_KEEP_CONNECTION;
end;
end;
function GetResponseHeader(const hRequest: Pointer): string;
var
dwSize, Index: DWORD;
szBuff: array [0..1024] of Char;
begin
Index:= 0;
dwSize:= SizeOf(szBuff);
HttpQueryInfo(hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, @szBuff, dwSize, Index);
Result:= PChar(@szBuff);
end;
function GetStatus(const hRequest: Pointer): DWORD;
var
dwSize, dwStatus, Index: DWORD;
begin
Index:= 0;
dwSize:= SizeOf(dwStatus);
HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE or HTTP_QUERY_FLAG_NUMBER, @dwStatus, dwSize, Index);
Result:= dwStatus;
end;
function AddSecurityFlags(httpReq: Pointer): Boolean;
var
dwSize, dwFlags: DWORD;
begin
Result:= False;
dwSize:= SizeOf(dwFlags); // Get the current security flags
if (InternetQueryOption(httpReq, INTERNET_OPTION_SECURITY_FLAGS, @dwFlags, dwSize)) then
begin // Add desired flags
dwFlags:= dwFlags
or SECURITY_FLAG_IGNORE_UNKNOWN_CA
or SECURITY_FLAG_IGNORE_CERT_CN_INVALID
or SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
or SECURITY_FLAG_IGNORE_REVOCATION;
Result:= (InternetSetOption(httpReq,
INTERNET_OPTION_SECURITY_FLAGS,
@dwFlags,
dwSize));
end
end;
function SendRequest(httpRequest: Pointer; AType_Access, AParam: string): boolean;
begin
case FPostData of
False: Result:= HttpSendRequest(httpRequest, nil, 0, nil, 0);
True: Result:= HttpSendRequest(httpRequest, PChar(AType_Access), Length(AType_Access), PChar(AParam), Length(AParam));
end;
end;
var
httpSession, httpConnect, httpRequest: HINTERNET;
bytes, b, pos: Cardinal;
hostname, script: string;
Flags_connection, Flags_Request: Cardinal;
DlgError: DWORD;
begin
Result:= EmptyAnsiStr;
hostname:= GetHostName(AURL);
script:= GetScriptName(AURL, hostname);
if not FPostData then
if FParam <> EmptyStr then
if script[Length(script)] = '?' then
script:= script + FParam
else
script:= script + '?' + FParam;
try
SetFlags(AURL, Flags_connection, Flags_Request);
httpSession:= InternetOpen(PChar(FClientName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(httpSession) then
try
httpConnect:= InternetConnect(httpSession, PChar(hostname), Flags_connection, nil, nil, INTERNET_SERVICE_HTTP, 0, 0);
if Assigned(httpConnect) then
try
httpRequest:= HttpOpenRequest(httpConnect, PChar(FMethod), PChar(script), HTTP_VERSION, nil, nil, Flags_Request, 0);
if Assigned(httpRequest) then
try
AddSecurityFlags(httpRequest);
SendRequest(httpRequest, FType_Access, FParam);
if GetStatus(httpRequest) = HTTP_STATUS_DENIED then
begin
if FLogin <> EmptyStr then
begin
InternetSetOption(httpRequest, INTERNET_OPTION_USERNAME, PChar(FLogin), SizeOf(FLogin));
InternetSetOption(httpRequest, INTERNET_OPTION_PASSWORD, PChar(FPass), SizeOf(FPass));
end
else
begin
DlgError:= InternetErrorDlg(FHWND, httpRequest,
ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED,
FLAGS_ERROR_UI_FILTER_FOR_ERRORS
or FLAGS_ERROR_UI_FLAGS_GENERATE_DATA
//or FLAGS_ERROR_UI_SERIALIZE_DIALOGS
or FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS,
PPointer(nil)^ );
if DlgError = 0 then
begin
Result:= AnsiString('Access Denied! Credential Entry Canceled.'
+ sLineBreak + SysErrorMessage(GetLastError));
Exit;
end;
end;
SendRequest(httpRequest, FType_Access, FParam);
end;
if GetStatus(httpRequest) = HTTP_STATUS_OK then
begin
pos:= 1;
b:= 1;
while b > 0 do
begin
if not InternetQueryDataAvailable(httpRequest, bytes, 0, 0) then
Result:= AnsiString(SysErrorMessage(GetLastError));
SetLength(Result, Cardinal(Length(Result)) + bytes);
InternetReadFile(httpRequest, @Result[Pos], bytes, b);
Inc(Pos, b);
end;
Result:= Result + AnsiString(SysErrorMessage(GetLastError));
end else
Result:= AnsiString(SysErrorMessage(GetLastError));
finally
InternetCloseHandle(httpRequest);
end else
Result:= AnsiString(SysErrorMessage(GetLastError));
finally
InternetCloseHandle(httpConnect);
end else
Result:= AnsiString(sLineBreak + SysErrorMessage(GetLastError));
finally
InternetCloseHandle(httpSession);
end else
Result:= AnsiString(SysErrorMessage(GetLastError));
except
On E: Exception do
Result:= AnsiString('Error! ' + E.ClassName + ': ' + E.Message);
end;
end;
end.
uses
..., WinInet;
...
Client:= TWinInet.Create(FrmTesting.Handle);
with Client do
try
if FrmTesting.CheckBox1.Checked then
begin
Login:= 'Domain\login';
Pass:= 'Password';
end;
FHTTPResult:= GetHTTP(FrmTesting.Edt1.Text);
finally
FreeAndNil(Client);
end;