delphi中如何设置dcef3的代理服务器setproxy?

代理服务器(Proxy Server)是一种重要的服务器安全功能,它的工作主要在开放系统互联(OSI)模型的会话层,从而起到防火墙的作用。代理服务器大多被用来连接INTERNET(国际互联网)和Local Area Network(局域网)。delphi中的tChromium控件dcef3如何设置代理服务器呢?

  1. 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;
  2. 在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
    24
    procedure 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.
  3. 在dcef3中如何动态设置代理服务器setproxy?
    前面已经说过,如果不在命令行中设置代理服务器,那么dcef是默认使用的ie代理服务器,要想动态设置代理服务器,我们不在dcef的命令行参数设置代理,然后使用开头的动态设置ie代理服务器的代码,dcef3的代理服务器就是动态的了!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
System network settings
The Chromium network stack uses the system network settings so that users and administrators can control the network settings of all applications easily. The network settings include:
proxy settings
SSL/TLS settings
certificate revocation check settings
certificate and private key stores
So far this design decision has worked well. The only network settings that some users ask for an alternative to system settings are proxy settings. For this we recently added some command-line options that allow you to run Chromium with custom proxy settings.
Preference service for network settings

Although the system network settings have been sufficient for our network stack, eventually there will be some configuration settings specific to our network stack, so we need to have our own preference service for those settings. See also issue 266, in which some Firefox users demand that we not use the WinInet proxy settings (the de facto system proxy settings on Windows).
Command-line options for proxy settings

Chrome supports the following proxy-related command line arguments:

–no-proxy-server

This tells Chrome not to use a Proxy. It overrides any other proxy settings provided.

–proxy-auto-detect

This tells Chrome to try and automatically detect your proxy configuration. This flag is ignored if –proxy-server is also provided.

–proxy-server==[:][;…] | [:] | “direct://”

This tells Chrome to use a custom proxy configuration. You can specify a custom proxy configuration in three ways:

1) By providing a semi-colon-separated mapping of list scheme to url/port pairs.
For example, you can specify:
–proxy-server=”http=foopy:80;ftp=foopy2″
to use HTTP proxy “foopy:80” for http URLs and HTTP proxy “foopy2:80″ for ftp URLs.

2) By providing a single uri with optional port to use for all URLs.
For example:
–proxy-server=”foopy:8080”
will use the proxy at foopy:8080 for all traffic.

3) By using the special “direct://” value.
–proxy-server=”direct://” will cause all connections to not use a proxy.

–proxy-bypass-list=(|)[:][;…]

This tells chrome to bypass any specified proxy for the given semi-colon-separated list of hosts. This flag must be used (or rather, only has an effect) in tandem with –proxy-server.
Note that trailing-domain matching doesn’t require “.” separators so “*google.com” will match “igoogle.com” for example.

For example,
–proxy-server=”foopy:8080″ –proxy-bypass-list=”*.google.com;*foo.com;127.0.0.1:8080″
will use the proxy server “foopy” on port 8080 for all hosts except those pointing to *.google.com, those pointing to *foo.com and those pointing to localhost on port 8080.
igoogle.com requests would still be proxied. ifoo.com requests would not be proxied since *foo, not *.foo was specified.

–proxy-pac-url=

This tells Chrome to use the PAC file at the specified URL.

For example,
–proxy-pac-url=”http://wpad/windows.pac”
will tell Chrome to resolve proxy information for URL requests using the windows.pac file.
-------------本文已结束赏个小钱吧-------------
×

感谢您的支持,我们会一直保持!

扫码支持
请土豪扫码随意打赏

打开微信扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

64.7K

相关文章推荐