delphi 设置WebBrowser 代理服务器 与 UserAgent  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.035851001739502 seconds