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

_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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值