2010-01-06 2 views
9

나는 Indy components을 사용하여 인터넷상의 웹 서버와 통신하는 델파이 애플리케이션을 가지고있다. 대부분의 응용 프로그램 사용자는 직접 인터넷에 연결되어 있지만 일부는 로컬 네트워크의 프록시 서버 뒤에 있습니다. I는 아주 솔직히 Internet Options/Connections/LAN Settings dialogDelphi 응용 프로그램이 Windows PC의 네트워크 프록시 설정을 어떻게 감지합니까?

alt text http://toybase.files.wordpress.com/2008/11/ie-proxy-settings.png

자신의 프록시 서버를 조회하는 대부분의 사람들이 알고 있거나이 설정이 무엇인지 상관하지 않습니다 사용자를 요청하고 싶지 않아요.

Delphi-7의 일부 시스템 호출을 통해이 정보를 얻을 수 있습니까?

감사합니다.

답변

13

Via WinAPI - WinHttpGetIEProxyConfigForCurrentUser. 당신은 MS의 긴 WINAPI 이름을 사랑해야합니다^_ ^. 영업 편집 후

: 당신은 레지스트리에서 읽을 수 AFAIR은 여기에 위치 할 것입니다 :

[ HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings ] 
+7

+1하지만 실수가 아니라면 이는 IE에만 ​​해당됩니다. Firefox 및 다른 브라우저는 자체 Proxy 설정을 유지합니다. –

+0

사실입니다.하지만 OP가 시스템 호출을 통해이를 얻으 려한다면, 그게 그가 한 일이라고 가정했습니다. –

+1

고마워요! 이제 내가 무엇을 검색해야하는지 알았습니다. 여기에 몇 가지 코드가 있습니다. http://coding.derkeiler.com/Archive/Delphi/borland.public.delphi.nativeapi/2004-01/0205.html – devstopfix

1

당신은에 따라 여러 가지 다른 위치에있을 수있는 브라우저에서 설정 프록시를 얻을 것이다 사용중인 브라우저

네트워크의 프록시 설정을 자동으로 감지하는 Web Proxy Autodiscovery Protocol을 조사해보십시오.

+0

사용자는 분명히있을 것입니다. IE를 사용하여 :)하지만 링크에 감사드립니다! – devstopfix

2

Kornel Kisielewiczanswer에 대한 델파이 코드 :

uses Registry, Windows; 

function detectIEProxyServer() : string; 
begin 
    with TRegistry.Create do 
    try 
     RootKey := HKEY_CURRENT_USER; 
     if OpenKey('\Software\Microsoft\Windows\CurrentVersion\Internet Settings', False) then begin 
      Result := ReadString('ProxyServer'); 
      CloseKey; 
     end 
     else 
      Result := ''; 
    finally 
     Free; 
    end; 
end; 
+0

NB : TRegistry.ReadString() : "레지스트리 항목에 문자열 이외의 것이 있으면 예외가 발생합니다." – devstopfix

3

여기에 직접 레지스트리 액세스를 필요로하지 않습니다 내가 사용하는 또 다른 방법입니다. 이것은 D2007에서 작동하지만 D7에서 작동하지 않는 이유를 알 수 없습니다.

uses 
    WinInet, 
    SysUtils; 

function UseIEProxyInfo(var ProxyHost: String; var ProxyPort: Integer): Boolean; 
var 
    ProxyInfo: PInternetProxyInfo; 
    Len: LongWord; 
    ProxyDetails: String; 
    s2: String; 
    i1: Integer; 

    procedure RemoveProtocol(var str: string); 
    var 
    i1 : integer; 
    begin 
    i1 := PosText('://', str); 
    if i1 > 0 then 
     Delete(str, 1, i1 + 2); 
    i1 := PosText('http=', str); 
    if i1 > 0 then begin 
     Delete(str, 1, i1 + 4); 
     str := SubStr(str, 1, ' '); 
    end; 
    end; 

begin 
    Result := False; 

    Len := 4096; 
    GetMem(ProxyInfo, Len); 
    try 
    if InternetQueryOption(nil, INTERNET_OPTION_PROXY, ProxyInfo, Len) then 
    begin 
     if ProxyInfo^.dwAccessType = INTERNET_OPEN_TYPE_PROXY then 
     begin 
     Result := True; 
     ProxyDetails := ProxyInfo^.lpszProxy; 

     RemoveProtocol(ProxyDetails); 
     s2 := SubStr(ProxyDetails, 2, ':'); 
     if s2 <> '' then 
     begin 
      try 
      i1 := StrToInt(s2); 
      except 
      i1 := -1; 
      end; 

      if i1 <> -1 then 
      begin 
      ProxyHost := SubStr(ProxyDetails, 1, ':'); 
      ProxyPort := i1; 
      end; 
     end; 
     end; 
    end; 
    finally 
    FreeMem(ProxyInfo); 
    end; 
end; 
+0

SubStr 함수의 정의를 아는 것이 좋을 것입니다. SubStr 함수는 여기에서 완전히 명백하지 않습니다. – mj2008

+1

@ mj2008 : madExcept 예외 처리 라이브러리의 madStrings.pas 유닛에있는 함수에 대한 참조입니다. 온라인 도움말은 http://help.madshi.net/StringSub.htm에서 찾을 수 있습니다. –