Proxy
tenho a unit abaixo que configura proxy.
Ela funciona... porem meu proxy ultiliza usuario e senha....
Alguem sabe como utilizar um proxy com usuario e senha ?
unit e0_Proxy;
interface
procedure SaveBeginInetSetting;
function RestoreBeginInetSetting:boolean;
function InetSessionToUserSetting(aEnProxy:boolean;
aStrIP,aStrPort:string):boolean;
function InetSessionToRegistrySetting:boolean;
implementation
uses windows,WinInet,UrlMon,
SysUtils;
var spBeginProxyStruct:PInternetProxyInfo;
len_spBeginProxyStruct:DWORD;
procedure SaveBeginInetSetting;
begin
InternetQueryOption
(nil,INTERNET_OPTION_PROXY,nil,len_spBeginProxyStruct);
spBeginProxyStruct:=AllocMem(len_spBeginProxyStruct);
InternetQueryOption(nil,INTERNET_OPTION_PROXY,spBeginProxyStruct,len_spBeginProxyStruct);
end;
function RestoreBeginInetSetting:boolean;
var
dreserved:dword;
x:dword;
p : INTERNET_PROXY_INFO;
begin
result := false;
p.dwAccessType := spBeginProxyStruct^.dwAccessType;
p.lpszProxyBypass := spBeginProxyStruct^.lpszProxyBypass;
p.lpszProxy := spBeginProxyStruct^.lpszProxy;
x := sizeof(p);
dreserved := 0;
if UrlMkSetSessionOption(INTERNET_OPTION_PROXY,@p,x,dreserved)<>S_Ok
then begin
Exit;
end;
result := true;
end;
function InetSessionToUserSetting(aEnProxy:boolean;
aStrIP,aStrPort:string):boolean;
var
p : INTERNET_PROXY_INFO;
x : integer;
dreserved : dword;
begin
result := false;
FillChar(p,sizeof(p),0);
if aEnProxy then begin
p.dwAccessType := INTERNET_OPEN_TYPE_PROXY;
p.lpszProxy := PChar(aStrIP+´:´+aStrPort);
end
else begin
p.dwAccessType := INTERNET_OPEN_TYPE_DIRECT;
p.lpszProxy := ´´;
end;
p.lpszProxyBypass := ´´;
x := sizeof(p);
dreserved := 0;
if UrlMkSetSessionOption(INTERNET_OPTION_PROXY,@p,x,dreserved)<>S_OK then
begin
Exit;
end;
result := true;
end;
function InetSessionToRegistrySetting:boolean;
var
hk : HKEY;
s : string;
BufSize : integer;
posStr : integer;
retType : DWORD;
isUsingProxy : DWORD;
begin
result := false;
s := ´´;
if RegOpenKeyEx(HKEY_CURRENT_USER,
´SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings´,
0,
KEY_ALL_ACCESS,
hk) = ERROR_SUCCESS then
begin
BufSize := SizeOf(isUsingProxy);
isUsingProxy := 0;
retType := REG_DWORD;
RegQueryValueEx(hk,
´ProxyEnable´,
nil,
@retType,
@isUsingProxy,
@bufSize);
if isUsingProxy > 0 then
begin
SetLength(s, MAX_PATH);
BufSize := length(s);
FillChar(s[1], MAX_PATH, #0);
retType := REG_NONE;
RegQueryValueEx(hk,
´ProxyServer´,
nil,
@retType,
@s[1],
@bufSize);
SetLength(s, bufsize);
if bufsize > 0 then
if s[length(s)] = 0 then SetLength(s, length(s)-1);
if length(s) > 0 then
begin
posStr := Pos(´http=´, LowerCase(s));
if posStr > 0 then
s := Copy(s, posStr+5, length(s));
posStr := Pos(´;´, s);
if posStr > 0 then
s := Copy(s, 1, posStr-1);
result := InetSessionToUserSetting(true,s,´´);
end;
end
else result := InetSessionToUserSetting(false,´´,´´);
RegCloseKey(hk);
end;
end;
end.
Ela funciona... porem meu proxy ultiliza usuario e senha....
Alguem sabe como utilizar um proxy com usuario e senha ?
unit e0_Proxy;
interface
procedure SaveBeginInetSetting;
function RestoreBeginInetSetting:boolean;
function InetSessionToUserSetting(aEnProxy:boolean;
aStrIP,aStrPort:string):boolean;
function InetSessionToRegistrySetting:boolean;
implementation
uses windows,WinInet,UrlMon,
SysUtils;
var spBeginProxyStruct:PInternetProxyInfo;
len_spBeginProxyStruct:DWORD;
procedure SaveBeginInetSetting;
begin
InternetQueryOption
(nil,INTERNET_OPTION_PROXY,nil,len_spBeginProxyStruct);
spBeginProxyStruct:=AllocMem(len_spBeginProxyStruct);
InternetQueryOption(nil,INTERNET_OPTION_PROXY,spBeginProxyStruct,len_spBeginProxyStruct);
end;
function RestoreBeginInetSetting:boolean;
var
dreserved:dword;
x:dword;
p : INTERNET_PROXY_INFO;
begin
result := false;
p.dwAccessType := spBeginProxyStruct^.dwAccessType;
p.lpszProxyBypass := spBeginProxyStruct^.lpszProxyBypass;
p.lpszProxy := spBeginProxyStruct^.lpszProxy;
x := sizeof(p);
dreserved := 0;
if UrlMkSetSessionOption(INTERNET_OPTION_PROXY,@p,x,dreserved)<>S_Ok
then begin
Exit;
end;
result := true;
end;
function InetSessionToUserSetting(aEnProxy:boolean;
aStrIP,aStrPort:string):boolean;
var
p : INTERNET_PROXY_INFO;
x : integer;
dreserved : dword;
begin
result := false;
FillChar(p,sizeof(p),0);
if aEnProxy then begin
p.dwAccessType := INTERNET_OPEN_TYPE_PROXY;
p.lpszProxy := PChar(aStrIP+´:´+aStrPort);
end
else begin
p.dwAccessType := INTERNET_OPEN_TYPE_DIRECT;
p.lpszProxy := ´´;
end;
p.lpszProxyBypass := ´´;
x := sizeof(p);
dreserved := 0;
if UrlMkSetSessionOption(INTERNET_OPTION_PROXY,@p,x,dreserved)<>S_OK then
begin
Exit;
end;
result := true;
end;
function InetSessionToRegistrySetting:boolean;
var
hk : HKEY;
s : string;
BufSize : integer;
posStr : integer;
retType : DWORD;
isUsingProxy : DWORD;
begin
result := false;
s := ´´;
if RegOpenKeyEx(HKEY_CURRENT_USER,
´SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings´,
0,
KEY_ALL_ACCESS,
hk) = ERROR_SUCCESS then
begin
BufSize := SizeOf(isUsingProxy);
isUsingProxy := 0;
retType := REG_DWORD;
RegQueryValueEx(hk,
´ProxyEnable´,
nil,
@retType,
@isUsingProxy,
@bufSize);
if isUsingProxy > 0 then
begin
SetLength(s, MAX_PATH);
BufSize := length(s);
FillChar(s[1], MAX_PATH, #0);
retType := REG_NONE;
RegQueryValueEx(hk,
´ProxyServer´,
nil,
@retType,
@s[1],
@bufSize);
SetLength(s, bufsize);
if bufsize > 0 then
if s[length(s)] = 0 then SetLength(s, length(s)-1);
if length(s) > 0 then
begin
posStr := Pos(´http=´, LowerCase(s));
if posStr > 0 then
s := Copy(s, posStr+5, length(s));
posStr := Pos(´;´, s);
if posStr > 0 then
s := Copy(s, 1, posStr-1);
result := InetSessionToUserSetting(true,s,´´);
end;
end
else result := InetSessionToUserSetting(false,´´,´´);
RegCloseKey(hk);
end;
end;
end.
Dicipulofer
Curtidas 0
Respostas
Dicipulofer
25/07/2003
Por favor me deem uma ajuda !
GOSTEI 0
Guibas
25/07/2003
como vc usou essa unit ... pq naum consegui
alguem sabe como?
tenho um programa ele funciona normalmente no serviudor, mas qdo coloco na maquina cliente não funciona... o mesmo aconte com mirc, kazaa, mas qdo configuro o a opção proxy nesses pogramas ele funcionam.... tem como colocar um opção dessa no programa em delphi pra reconhecer conexão por proxy???
grato
Guilherme
alguem sabe como?
tenho um programa ele funciona normalmente no serviudor, mas qdo coloco na maquina cliente não funciona... o mesmo aconte com mirc, kazaa, mas qdo configuro o a opção proxy nesses pogramas ele funcionam.... tem como colocar um opção dessa no programa em delphi pra reconhecer conexão por proxy???
grato
Guilherme
GOSTEI 0