代理服务器(Proxy Server)是一种重要的服务器安全功能,它的工作主要在开放系统互联(OSI)模型的会话层,从而起到防火墙的作用。代理服务器大多被用来连接INTERNET(国际互联网)和Local Area Network(局域网)。delphi中的tChromium控件dcef3如何设置代理服务器呢?
- delphi中webbrowser设置代理服务器是这样的!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17{-------------------------------------------------------------------------------
过程名: SetProcessProxy
作者: kelei
日期: 2013.08.03
参数: aProxyServer代理服务器; aProxyPort代理服务器端口
返回值: True设置成功
SetProcessProxy('127.0.0.1', 80);
-------------------------------------------------------------------------------}
function SetProcessProxy(const aProxyServer: string; const aProxyPort: Integer): Boolean;
var
vProxyInfo: TInternetProxyInfo;
begin
vProxyInfo.dwAccessType := INTERNET_OPEN_TYPE_PROXY;
vProxyInfo.lpszProxy := PChar(Format('http=%s:%d', [aProxyServer, aProxyPort]));
vProxyInfo.lpszProxyBypass := PChar('');
Result := UrlMkSetSessionOption(INTERNET_OPTION_PROXY, @vProxyInfo, SizeOf(vProxyInfo, 0) = S_OK;
end; - 在dcef3中如何静态设置代理服务器呢?
静态设置方法在dpr中添加启动命令行参数,如果不添加命令行参数设置代理服务器,那么dcef3默认是使用的ie的代理服务器:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24procedure AppendCefCmdline(const processType: ustring; const cmd: ICefCommandLine);
begin
cmd.AppendSwitchWithValue('proxy-server','http://218.189.26.20:8080');//设置http代理服务器
cmd.AppendSwitchWithValue('proxy-server','https://218.189.26.20:8082');//设置https代理服务器
cmd.AppendSwitchWithValue('proxy-server','ftp://218.189.26.20:21');//设置ftp代理服务器
cmd.AppendSwitchWithValue('proxy-server','socks://202.116.0.188:3128')//设置SOCKS代理服务器
cmd.AppendSwitchWithValue('proxy-server','sock4://202.116.0.188:1080')//设置sock4代理服务器
cmd.AppendSwitchWithValue('proxy-server','sock5://202.116.0.188:1081')//设置sock5代理服务器
//cmd.AppendSwitchWithValue('proxy-server','direct://')//所有连接不使用代理
//cmd.AppendSwitchWithValue('proxy-server','https=127.0.0.1:80;http=socks4://bnwin.com:1080')//同时设置https和sock4代理服务器
cmd.AppendSwitchWithValue('proxy-bypass-list','127.*,192.168.*,10.10.*,193.9.162.*');//不使用代理服务器的地址
//cmd.AppendSwitch('--no-proxy-server');//禁止代理服务器
//cmd.AppendSwitch('--proxy-auto-detect');//自动检测代理配置
//cmd.AppendSwitchWithValue('proxy-pac-url','http://www.bnwinn.com/proxy.pac')//代理使用指定URL中的PAC文件
//cmd.AppendSwitch('--winhttp-proxy-resolver');//代理在IE中运行正常,但在chrome中失败,可以添加此flag
end;
begin
CefOnBeforeCommandLineProcessing :=AppendCefCmdline; //指定dcef启动命令行
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end. - 在dcef3中如何动态设置代理服务器setproxy?
前面已经说过,如果不在命令行中设置代理服务器,那么dcef是默认使用的ie代理服务器,要想动态设置代理服务器,我们不在dcef的命令行参数设置代理,然后使用开头的动态设置ie代理服务器的代码,dcef3的代理服务器就是动态的了!
1 | System network settings |