Autor Beitrag
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Do 07.08.08 10:45 
Hallo Community! :wink2:

Beim entwickeln von Internet Anwendungen macht es häufig sinn die IE Proxy Einstellungen mit zu verwenden um den User das manuelle einstellen abzunehmen. Windows bietet die Möglichkeit diese Informationen abzufragen. Die folgende Funktion nimmt dem Entwickler die nötigen Schritte ab und liefert ein Record (vom Typ TIEProxyServer) zurück welches die Proxy Einstellungen für das angegebene Protokoll (Parameter aProtocol) enthält.

ausblenden volle Höhe Funktion GetIEProxyServer
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
uses
  SysUtils, WinInet;

type
  TIEProxyServer = record
    Protocol,
    Server: string;
    Port: Integer
  end;

function GetIEProxyServer (aProtocol: string) : TIEProxyServer;
// Ursprüngliche Version vom 08-04-2004 von shmia

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

var
  i: Integer;
  ProxyInfoStr : string;
begin
  Result.Protocol := aProtocol;
  Result.Server := '';
  Result.Port := 0;

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

  aProtocol := aProtocol + '=';

  i := Pos (aProtocol, ProxyInfoStr);
  if i > 0 then
  begin
    Delete (ProxyInfoStr, 1, i + Length (aProtocol));
    i := Pos (';', Result.Server);
    if i > 0 then
      ProxyInfoStr := Copy (ProxyInfoStr, 1, i - 1);
  end;

  i := Pos (':', ProxyInfoStr);
  if i > 0 then
  begin
    Result.Port := StrToIntDef (Copy(ProxyInfoStr, i + 1, Length (ProxyInfoStr) - i), 0);
    Result.Server := Copy (ProxyInfoStr, 1, i - 1)
  end
end;

_________________
Ein Nutzer der Ecke ;-)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 15.12.08 16:37 
Moin!

Kannst du bitte mal ein Beispiel für die Nutzung geben? Ich habe es so versucht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
  var
    IEProxyServer: TIEProxyServer;
begin
  IEProxyServer := GetIEProxyServer('http');
  Memo1.Lines.Add(IEProxyServer.Protocol);
  Memo1.Lines.Add(IEProxyServer.Server);
end;
bekomme aber nur Leerstrings zurück (übrigens schon als Ergebnis von GetProxyInformation(), hab´s mir zwischendurch mal mit ausgeben lassen). :nixweiss:

Danke. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Martin1966 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Di 08.02.11 11:40 
oje, tut mir leid. deine Nachricht habe ich erst jetzt gelesen. :-(

user profile iconNarses hat folgendes geschrieben Zum zitierten Posting springen:
bekomme aber nur Leerstrings zurück (übrigens schon als Ergebnis von GetProxyInformation(), hab´s mir zwischendurch mal mit ausgeben lassen). :nixweiss:


ich hab den code gerade noch mal getestet (s. Screenshots) und bei mir klappt es. :nixweiss: vielleicht hat jemand eine Idee warum es bei Narses nicht funktioniert.

proxy1
proxy2


Inline-Anhänge (ein- / ausblenden)
_________________
Ein Nutzer der Ecke ;-)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 08.02.11 13:49 
Moin!

user profile iconMartin1966 hat folgendes geschrieben Zum zitierten Posting springen:
oje, tut mir leid. deine Nachricht habe ich erst jetzt gelesen. :-(
Kein Problem, war ja nicht drauf angewiesen. ;)

user profile iconMartin1966 hat folgendes geschrieben Zum zitierten Posting springen:
user profile iconNarses hat folgendes geschrieben Zum zitierten Posting springen:
bekomme aber nur Leerstrings zurück (übrigens schon als Ergebnis von GetProxyInformation(), hab´s mir zwischendurch mal mit ausgeben lassen). :nixweiss:
ich hab den code gerade noch mal getestet (s. Screenshots) und bei mir klappt es.
Hm, vielleicht liegt´s ja daran, dass ich keine statische Proxy-Config verwende: :idea:
Proxy
Das ist allerdings schade, ich dache, so könnte man auch an die aktuelle Config kommen. :|

cu
Narses


Inline-Anhänge (ein- / ausblenden)
_________________
There are 10 types of people - those who understand binary and those who don´t.