Lm th? no ? l?p tr?nh truy v?n v ?t thi?t ?t ?y quy?n d?i Internet Explorer

D?ch tiu ? D?ch tiu ?
ID c?a bi: 226473 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

TM T?T

Bi vi?t gi?i thch b?c c?n thi?t ? l?p tr?nh truy v?n v thi?t l?p cc proxy thi?t ?t thng tin cho Internet Explorer.

Theo Internet Explorer 4.x v tr?c , InternetSetOption v InternetQueryOption cc API ?c s? d?ng v?i c? INTERNET_OPTION_PROXY. Trong khi ty ch?n ny s? v?n lm vi?c d?i Internet Explorer 5, nhi?u ty ch?n k?t n?i ? ?c gi?i thi?u trong phin b?n m?i. ?c i?u ny, c? INTERNET_OPTION_PROXY s? tr? l?i ch? l my ch? proxy "t?nh" thi?t l?p. Cc ty ch?n t?nh l thng tin my ch? ?y quy?n ?c lu d?i HKEY_CURRENT_USER hive nhi?u theo cng m?t cch n ? theo Internet Explorer 4.0

Chu y INTERNET_OPTION_PROXY khng v?nh vi?n thay ?i cc thi?t ?t. N th?c hi?n i?u ny cho qu tr?nh hi?n t?i ch? khi m?t x? l? NULL ?c s? d?ng. Tuy nhin, n c?ng c th? thay ?i cc thi?t l?p trn m?t c s? cho m?i phin lm vi?c n?u m?t x? l? h?p l? phin ?c g?i trong (phin x? l? ?c thu ?c b?ng cch s? d?ng InternetOpen() API).

N?u theo Internet Explorer 5, b?n ch? ?nh m?t ty ch?n k?t n?i khc nhau (ch?ng h?n nh m?t quay s? k?t n?i) theo m?c ?nh, c th? thng tin ?y quy?n b?n c ?c b?ng cch s? d?ng INTERNET_OPTION_PROXY c? c th? khng chnh xc cho Internet Explorer phin hi?n th?i. V? l? do ny, d?i Internet Explorer 5, khuyn r?ng INTERNET_OPTION_PER_CONNECTION_OPTION ?c s? d?ng ? thay th?.

Chu y INTERNET_OPTION_PER_CONNECTION_OPTION gy ra cc thi?t ?t ph?i ?c thay ?i trn c s? ton h? th?ng khi m?t x? l? NULL ?c s? d?ng. ? ph?n nh chnh xc thi?t ?t ?y quy?n ton c?u, b?n ph?i g?i cho cc InternetSetOption ch?c nng v?i INTERNET_OPTION_REFRESH ty ch?n c?. Ho?c, ? thi?t l?p cc ci ?t trn m?t c s? cho m?i phin lm vi?c, m?t x? l? h?p l? phin c th? ?c s? d?ng.

Chu y l v?n c?n c th? thay ?i thng tin ?y quy?n cho qu tr?nh whgke m khng ?nh h?ng ?n ton c?u my thi?t l?p trong Internet Explorer 5 v phin b?n m?i nh?t. ? th?c hi?n vi?c ny, b?n ph?i g?i cho cc InternetSetOption ch?c nng ngy x? l? ?c tr? l?i b?i cc InternetOpen ch?c nng b?ng cch s? d?ng ty ch?n INTERNET_OPTION_PER_CONNECTION_OPTION. V d? m? sau thay ?i proxy cho ton b? qu tr?nh m?c d cc hInternet x? l? ng c?a v khng ?c s? d?ng cho yu c?u th?c t?.
HINTERNET hInternet = InternetOpen(szAppName, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
InternetSetOption(hInternet, INTERNET_OPTION_PER_CONNECTION_OPTION, ...);
InternetCloseHandle (hInternet);

THNG TIN THM

Theo Internet Explorer 4.x, m?t c ch? tiu bi?u ? truy v?n thng tin proxy s? gi?ng nh th? ny:
unsigned long        nSize = 4096;
char                 szBuf[4096] = { 0 };
INTERNET_PROXY_INFO* pInfo = (INTERNET_PROXY_INFO*)szBuf;

if(!InternetQueryOption(NULL, INTERNET_OPTION_PROXY, pInfo, &nSize))
   printf("InternetQueryOption failed! (%d)\n", GetLastError());
				
Theo Internet Explorer 5, cch ?c ? ngh? l s? d?ng m? tng t? nh d?i y:
INTERNET_PER_CONN_OPTION_LIST    List;
INTERNET_PER_CONN_OPTION         Option[5];
unsigned long                    nSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);

Option[0].dwOption = INTERNET_PER_CONN_AUTOCONFIG_URL;
Option[1].dwOption = INTERNET_PER_CONN_AUTODISCOVERY_FLAGS;
Option[2].dwOption = INTERNET_PER_CONN_FLAGS;
Option[3].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
Option[4].dwOption = INTERNET_PER_CONN_PROXY_SERVER;

List.dwSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);
List.pszConnection = NULL;
List.dwOptionCount = 5;
List.dwOptionError = 0;
List.pOptions = Option;

if(!InternetQueryOption(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &List, &nSize))
   printf("InternetQueryOption failed! (%d)\n", GetLastError());
   if(Option[0].Value.pszValue != NULL)
   printf("%s\n", Option[0].Value.pszValue);

if((Option[2].Value.dwValue & PROXY_TYPE_AUTO_PROXY_URL) == PROXY_TYPE_AUTO_PROXY_URL)
  printf("PROXY_TYPE_AUTO_PROXY_URL\n");

if((Option[2].Value.dwValue & PROXY_TYPE_AUTO_DETECT) == PROXY_TYPE_AUTO_DETECT)
   printf("PROXY_TYPE_AUTO_DETECT\n");

INTERNET_VERSION_INFO      Version;
nSize = sizeof(INTERNET_VERSION_INFO);

InternetQueryOption(NULL, INTERNET_OPTION_VERSION, &Version, &nSize);

if(Option[0].Value.pszValue != NULL)
   GlobalFree(Option[0].Value.pszValue);

if(Option[3].Value.pszValue != NULL)
   GlobalFree(Option[3].Value.pszValue);

if(Option[4].Value.pszValue != NULL)
   GlobalFree(Option[4].Value.pszValue);
				
M? ? trn ch? ?nh k?t n?i b?ng cch thi?t l?p chu?i pszConnection trong c c?u INTERNET_PER_CONN_OPTION_LIST. B?ng cch ?t chu?i ny thnh NULL, thng tin c?u h?nh s? ?c l?y cho m?c ?nh (ho?c LAN) ci ?t.

Ty ch?n ?u tin (ty ch?n [0] INTERNET_PER_CONN_AUTOCONFIG_URL) s? tr? v? URL ?c ch? ?nh cho c?u h?nh t? ?ng c?a cc my ch? proxy. Ty ch?n th? hai (l?a ch?n [1] INTERNET_PER_CONN_AUTODISCOVERY_FLAG) s? pht hi?n hay khng t? ?ng pht hi?n ty ch?n ?c kch ho?t hay khng cho k?t n?i ?c ch? ra. L?a ch?n th? ba s? xc ?nh s? k?t h?p c?a l c? ? ?c thi?t l?p cho k?t n?i ny c? th?. Cu?i hai l?a ch?n tng ?ng v?i thng tin tng t? nh truy c?p whe INTERNET_OPTION_PROXY ?c s? d?ng trong Internet Explorer 4.x.

Nh b?n c?ng th?y, cc ty ch?n m c th? c ti?m nng tr? v? chu?i gi tr? ?c gi?i phng b?ng cch s? d?ng GlobalFree(). i?u ny l b?i v? b? ?m chu?i ?c phn b? cho b?n b?i th vi?n WinINet x? l?, v n ?n l?p tr?nh ? gi?i phng b? ?m sau khi s? d?ng n.

? c ?c thng tin cho m?t k?t n?i khc nhau, n gi?n ch? c?n thay ?i chu?i List.pszConnection ? tr? ?n Dial-Up thi?t l?p m?c b?n ang quan tm ?n n.

Tng t? nh v?y, ?t ?y quy?n thng tin, b?n s? s? d?ng k? thu?t tng t? nhng v?i InternetSetOption() thay vo , v d?:
INTERNET_PER_CONN_OPTION_LIST    List;
INTERNET_PER_CONN_OPTION         Option[1];
unsigned long                    nSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);

Option[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
Option[0].Value.pszValue = "http://myproxy:8080";

List.dwSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);
List.pszConnection = NULL;
List.dwOptionCount = 1;
List.dwOptionError = 0;
List.pOptions = Option;

if(!InternetSetOption(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &List, nSize))
   printf("InternetQueryOption failed! (%d)\n", GetLastError());

				
M?t l?n n?a, m?u ? trn s? thay ?i m?c ?nh (ho?c LAN) ci ?t (List.pszConnection == NULL). Trong m?u, thng tin my ch? ?y quy?n "t?nh" ?c thay ?i ? "http://myproxy" t?i c?ng 8080. Tng t? nh v?y b?n c?ng c th? thay ?i t? ?ng c?u h?nh URL:
INTERNET_PER_CONN_OPTION_LIST    List;
INTERNET_PER_CONN_OPTION         Option[2];
unsigned long                    nSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);

Option[0].dwOption = INTERNET_PER_CONN_AUTOCONFIG_URL;
Option[0].Value.pszValue = "http://myserver/get_proxy_info.dll";
Option[1].dwOption = INTERNET_PER_CONN_FLAGS;
Option[1].Value.dwValue = PROXY_TYPE_AUTO_PROXY_URL;

List.dwSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);
List.pszConnection = NULL;
List.dwOptionCount = 2;
List.dwOptionError = 0;
List.pOptions = Option;

if(!InternetSetOption(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &List, nSize))
   printf("InternetQueryOption failed! (%d)\n", GetLastError());
				
Khi b?n c?u h?nh Internet Explorer s? d?ng m?t my ch? proxy cho HTTP v i tr?c ti?p cho cc giao th?c khc, s? d?ng m? ? lm theo.

Chu y B? ?m ?c thng qua ? INTERNET_PER_CONN_PROXY_SERVER ? thi?t l?p cho m?i giao th?c (m? ny ?t ch? HTTP, v t?t c? cc giao th?c s? d?ng k?t n?i tr?c ti?p).

Chu y INTERNET_PER_CONN_FLAGS b? gi tr? cho c? hai lo?i Proxy (tr?c ti?p v thng qua proxy) trong m?t ph?n c?a m?ng danh sch ty ch?n, nh ?c hi?n th? d?i y trong cc m?.

Chu y B?n ph?i ho?c nh?ng l c? ? m?t ni. N?u b?n ?t cc c? trong m?t danh sch cc y?u t?, h? s? hi?n th? m?t cch chnh xc (ty ch?n Internet Explorer), nhng ch? l m?t trong nh?ng l c? (l ng?i ?u tin ?c thi?t l?p) s? lm vi?c.
int main(int argc, char * argv[]) 
{ 
char buff[256] = "http=http://<ProxyServerName>:80"; 
// To include server for FTP, HTTPS, and so on, use the string
// (ftp=http://<ProxyServerName>:80; https=https://<ProxyServerName>:80) 
INTERNET_PER_CONN_OPTION_LIST    List; 
INTERNET_PER_CONN_OPTION         Option[3]; 
unsigned long                    nSize = sizeof(INTERNET_PER_CONN_OPTION_LIST); 

Option[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER; 
Option[0].Value.pszValue = buff; 

Option[1].dwOption = INTERNET_PER_CONN_FLAGS; 
Option[1].Value.dwValue = PROXY_TYPE_PROXY; 
Option[1].Value.dwValue |= PROXY_TYPE_DIRECT; 
// This option sets all the possible connection types for the client. 
// This case specifies that the proxy can be used or direct connection is possible.

Option[2].dwOption = INTERNET_PER_CONN_PROXY_BYPASS; 
Option[2].Value.pszValue = "<local>"; 

 

List.dwSize = sizeof(INTERNET_PER_CONN_OPTION_LIST); 
List.pszConnection = NULL; 
List.dwOptionCount = 3; 
List.dwOptionError = 0; 
List.pOptions = Option; 

if(!InternetSetOption(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &List, nSize)) 
printf("InternetSetOption failed! (%d)\n", GetLastError()); 

InternetSetOption(NULL, INTERNET_OPTION_REFRESH, NULL,NULL); 
//The connection settings for other instances of Internet Explorer. 

return 0; 

}
				
M?u ? trn (m?t l?n n?a m?c ?nh ho?c thi?t l?p m?ng LAN), b?n ph?i ch? ?nh URL c?u h?nh proxy t? ?ng v ?t c? ty ch?n ? cho php c?u h?nh proxy t? ?ng.

THAM KH?O

MSDN WinInet API ti li?u, thng 4 nm 1999

Thu?c tnh

ID c?a bi: 226473 - L?n xem xt sau cng: 21 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Internet Explorer 4.01 Service Pack 1
T? kha:
kbhowto kbmt KB226473 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:226473
Khc t Ni dung trong C s Kin thc Khng con c h tr
Bi vi?t ny ni v? cc s?n ph?m m Microsoft khng c?n h? tr? n?a. Do , bi vi?t ny ?c cung c?p "nguyn b?n" v s? khng ?c c?p nh?t.

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com