[델파이] 프록시(Proxy) 설정
델파이2010. 12. 24. 11:27
unit ProxyUnit; interface uses Windows, Wininet; const INTERNET_PER_CONN_FLAGS = 1; INTERNET_PER_CONN_PROXY_SERVER = 2; INTERNET_PER_CONN_PROXY_BYPASS = 3; INTERNET_PER_CONN_AUTOCONFIG_URL = 4; INTERNET_PER_CONN_AUTODISCOVERY_FLAGS = 5; PROXY_TYPE_DIRECT = $00000001; PROXY_TYPE_PROXY = $00000002; INTERNET_OPTION_PER_CONNECTION_OPTION = 75; type INTERNET_PER_CONN_OPTION = record dwOption: DWORD; Value: record case Integer of 1: (dwValue: DWORD); 2: (pszValue: PAnsiChar); 3: (ftValue: TFileTime); end; end; LPINTERNET_PER_CONN_OPTION = ^INTERNET_PER_CONN_OPTION; INTERNET_PER_CONN_OPTION_LIST = record dwSize: DWORD; pszConnection: LPTSTR; dwOptionCount: DWORD; dwOptionError: DWORD; pOptions: LPINTERNET_PER_CONN_OPTION; end; LPINTERNET_PER_CONN_OPTION_LIST = ^INTERNET_PER_CONN_OPTION_LIST; procedure SetProxy(Con, ProxyServer: String); procedure DisableProxy(Con: String); implementation procedure SetProxy(Con, ProxyServer: String); var list: INTERNET_PER_CONN_OPTION_LIST; dwBufSize: DWORD; Options: array[1..2] of INTERNET_PER_CONN_OPTION; begin dwBufSize := sizeof(list); list.dwSize := sizeof(list); list.pszConnection := pchar(Con); list.dwOptionCount := High(Options); Options[1].dwOption := INTERNET_PER_CONN_FLAGS; Options[1].Value.dwValue := PROXY_TYPE_PROXY; Options[2].dwOption := INTERNET_PER_CONN_PROXY_SERVER; Options[2].Value.pszValue := PansiChar(ProxyServer); list.pOptions := @Options; InternetSetOption(nil, INTERNET_OPTION_PER_CONNECTION_OPTION, @list, dwBufSize); InternetSetOption(nil, INTERNET_OPTION_REFRESH, nil, 0); end; procedure DisableProxy(Con: String); var list: INTERNET_PER_CONN_OPTION_LIST; dwBufSize: DWORD; Options: array[1..2] of INTERNET_PER_CONN_OPTION; begin dwBufSize := sizeof(list); list.dwSize := sizeof(list); list.pszConnection := pchar(Con); list.dwOptionCount := High(Options); // the highest index of the array (in this case 3) Options[1].dwOption := INTERNET_PER_CONN_FLAGS; Options[1].Value.dwValue := PROXY_TYPE_DIRECT; Options[2].dwOption := INTERNET_PER_CONN_PROXY_SERVER; Options[2].Value.pszValue := PansiChar(''); list.pOptions := @Options; InternetSetOption(nil, INTERNET_OPTION_PER_CONNECTION_OPTION, @list, dwBufSize); InternetSetOption(nil, INTERNET_OPTION_REFRESH, nil, 0); end; end.
사용은 아래와 같이...
SetProxy('','localhost:8080');
DisableProxy('');
'델파이' 카테고리의 다른 글
[델파이] 콘솔 어플리케이션의 표준출력/표준에러 받아오기 (0) | 2011.12.28 |
---|---|
[델파이] SHDocVw_TLB (0) | 2010.12.21 |
[델파이] 예외 처리 클래스의 종류 (0) | 2009.11.13 |
[델파이] DLL Injection (1) | 2009.06.17 |
[델파이] 기본 함수 정리 (0) | 2009.06.15 |
델파이에서 메모리 누수 확인 (0) | 2009.04.20 |
IE 기본 툴바에 버튼 생성하기 (0) | 2009.03.10 |
현재 페이지의 모든 쿠키 읽어 오기 (0) | 2009.01.29 |
서버 상태 확인 (0) | 2009.01.12 |
BeforeNavigate2 이벤트에서 PostData 읽어오기 (GET 방식과 POST 방식의 구분) (0) | 2008.12.04 |