Delphi 设置WebBrowser 代理服务器 与 UserAgent


本文整理自网络,侵删。

 
uses UrlMon, WinInet;

{-------------------------------------------------------------------------------
  过程名:    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;

{-------------------------------------------------------------------------------
  过程名:    SetProcessUserAgent
  作者:      kelei
  日期:      2013.08.03
  参数:      aUserAgent HTTP请求头UserAgent内容
  返回值:    True设置成功
  SetProcessUserAgent('Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3')
-------------------------------------------------------------------------------}
function SetProcessUserAgent(const aUserAgent: string): Boolean;
begin
  Result := UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, PChar(aUserAgent), Length(aUserAgent), 0) = S_OK;
end;


另一个办法:http://delphitop.com/html/xitong/2995.html

相关阅读 >>

Delphi 利用tidencodermime tiddecodermime 组件字符串加密解密

Delphi2010中Delphi class explorer妙用

Delphi中带缓存的数据更新技术

Delphi取得桌面工作区域的大小

Delphi 获取鼠标坐标大全方法

Delphi 不重启不注销不关explorer刷新注册表

Delphi textfile读取文本文件

Delphi将n个相同字符提取到左边,m个相同字符提取到右边

Delphi setcursorpos函数在窗口上定位鼠标坐标

Delphi的unicode与gb2312转转换,汉字unicode转gb2312

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

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

评论

管理员已关闭评论功能...