Einzelnen Beitrag anzeigen

Benutzerbild von sx2008
sx2008

Registriert seit: 15. Feb 2008
Ort: Baden-Württemberg
2.332 Beiträge
 
Delphi 2007 Professional
 
#2

AW: [WinHTTP API] Proxyeinstellungen lesen und interpretieren

  Alt 13. Okt 2014, 20:54
Proxy Server Einstellungen des IE abfragen
Ich glaube in dem Code in noch ein Bug drin und deshalb habe ich mir das vor längerer Zeit umgeschrieben:
Delphi-Quellcode:
uses ...,WinInet;

function GetProxyInformation2(handle:HINTERNET):string;
var
  ProxyInfo: PInternetProxyInfo;
  Len: LongWord;
begin
   Result := '';
   Len := 4096;
   GetMem(ProxyInfo, Len);
   try
      if InternetQueryOption(handle, INTERNET_OPTION_PROXY, ProxyInfo, Len) then
         if ProxyInfo^.dwAccessType = INTERNET_OPEN_TYPE_PROXY then
         begin
            Result := ProxyInfo^.lpszProxy
         end;
   finally
      FreeMem(ProxyInfo);
   end;
end;


function GetProxyInformation:string;
begin
   Result := GetProxyInformation2(nil);
end;

{**************************************************************************
* NAME:    GetProxyServer
* DESC:    Proxy-Server Einstellungen abfragen
* PARAMS:  protocol => z.B. 'http' oder 'ftp'
*************************************************************************}

procedure GetProxyServer(protocol:string; var ProxyServer:string; var ProxyPort:Integer);
var
   i : Integer;
   proxyinfo : string;
begin
   ProxyServer := '';
   ProxyPort := 0;

   proxyinfo := GetProxyInformation;
   if proxyinfo = 'then
      Exit;

   protocol := AnsiLowerCase(protocol)+'=';

   i := Pos(protocol, proxyinfo);
   if i > 0 then
   begin
      Delete(proxyinfo, 1, i+Length(protocol)-1);
      i := Pos(';', proxyinfo);
      if i=0 then
         i := Pos(' ', proxyinfo);
      if i > 0 then
        proxyinfo := Copy(proxyinfo, 1, i-1);
   end;

   i := Pos(':', proxyinfo);
   if i > 0 then
   begin
      ProxyPort := StrToIntDef(Copy(proxyinfo, i+1, Length(proxyinfo)-i), 0);
      ProxyServer := Copy(proxyinfo, 1, i-1)
   end
end;
fork me on Github

Geändert von sx2008 (13. Okt 2014 um 20:57 Uhr)
  Mit Zitat antworten Zitat