通过代理服务器 访问 Internet页面。

来源:互联网 发布:团队文档库 mac 编辑:程序博客网 时间:2024/05/18 00:59

_hHTTPOpen=::InternetOpen(szAgent,            // agent name
            INTERNET_OPEN_TYPE_PRECONFIG, // proxy option
            "",              // proxy
            "",            // proxy bypass
            0);     // flags

 if(!_hHTTPOpen){
  _dwError=::GetLastError();
#ifdef _DEBUG
  LPVOID     lpMsgBuffer;
  DWORD dwRet=FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                NULL,
                ::GetLastError(),
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                reinterpret_cast<LPTSTR>(&lpMsgBuffer),
                0,
                NULL);
  OutputDebugString(reinterpret_cast<LPTSTR>(lpMsgBuffer));
  LocalFree(lpMsgBuffer);  
#endif
  return FALSE;
 } 

 _hHTTPConnection=::InternetConnect( _hHTTPOpen, // internet opened handle
               szAddress, // server name
               nPort, // ports
               szUserAccount, // user name
               szPassword, // password
               INTERNET_SERVICE_HTTP, // service type
               INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_CACHE_WRITE, // service option                              
               0); // context call-back option

 if(!_hHTTPConnection){  
  _dwError=::GetLastError();
  ::CloseHandle(_hHTTPOpen);
#ifdef _DEBUG
  LPVOID     lpMsgBuffer;
  DWORD dwRet=FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                NULL,
                ::GetLastError(),
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                reinterpret_cast<LPTSTR>(&lpMsgBuffer),
                0,
                NULL);
  OutputDebugString(reinterpret_cast<LPTSTR>(lpMsgBuffer));
  LocalFree(lpMsgBuffer);  
#endif
  return FALSE;
 }

 if(::InternetAttemptConnect(NULL)!=ERROR_SUCCESS){  
  _dwError=::GetLastError();
  ::CloseHandle(_hHTTPConnection);
  ::CloseHandle(_hHTTPOpen);
#ifdef _DEBUG
  LPVOID     lpMsgBuffer;
  DWORD dwRet=FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                NULL,
                ::GetLastError(),
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                reinterpret_cast<LPTSTR>(&lpMsgBuffer),
                0,
                NULL);
  OutputDebugString(reinterpret_cast<LPTSTR>(lpMsgBuffer));
  LocalFree(lpMsgBuffer);  
#endif
  return FALSE;
 }
 // Set Proxy
 if(1==nNeedProxy) 
 {
  /* set proxy information */
  INTERNET_PROXY_INFO   proxyinfo;
  proxyinfo.dwAccessType   =   INTERNET_OPEN_TYPE_PROXY;
  proxyinfo.lpszProxy   =  _szProxyList;
  proxyinfo.lpszProxyBypass   =   NULL;
  InternetSetOption(_hHTTPConnection,
       INTERNET_OPTION_PROXY,  
       (LPVOID)&proxyinfo,  
       sizeof(INTERNET_PROXY_INFO));
  InternetSetOption(_hHTTPConnection,INTERNET_OPTION_PROXY_USERNAME, _szProxyUserName,   strlen(_szProxyUserName)+1);
  InternetSetOption(_hHTTPConnection,INTERNET_OPTION_PROXY_PASSWORD,  _szProxyPassword,   strlen(_szProxyPassword)+1); 

 }
 return TRUE;

原创粉丝点击