Delphi 설정 WebBrowser 프록시 및 UserAgent

2996 단어 WebBrowser
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;

좋은 웹페이지 즐겨찾기