以下这段代码,是探测某个网页是否可以连接的,但返回值总有问题,无论如何返回的都是true,请高手看看问题在哪儿?
pConnection=Session.GetHttpConnection(g_strServerName,0,80,NULL,NULL);这一句中参数有问题吗?
bool getHttpConnection(LPCTSTR OriUrl) //探测是否可以连接某个网站
{
CString   g_strServerName=OriUrl;  
CInternetSession   Session;  
CHttpConnection*   pConnection=NULL;  
CHttpFile*   pFile1=NULL;       try     
{   
pConnection=Session.GetHttpConnection(g_strServerName,0,80,NULL,NULL);//用80端口连接,并返回值
  if   (pConnection !=   NULL)  //连接上了该网站     
  {   
CString   m_i;   
m_i="连接成功\r\n";   
        //m_ftpinfo   +=m_i;   
        //UpdateData(FALSE);   
 //do   something  

return true;
      }     pFile1->Close(); 
    delete []pFile1;
        Ses
印良智(印良智) 21:06:40
sion.Close(); 
}
catch   (CInternetException   *   pEx)
{     
CString   m_i;   
m_i="连接成功\r\n";   
        //m_ftpinfo   +=m_i;   
//        UpdateData(FALSE);  TCHAR   szError[1024]; 
if   (pEx->GetErrorMessage(szError,1024))     
{   
      
m_i=(CString)   szError;   
        //UpdateData(FALSE);   
return true;
}               
else
{     
AfxMessageBox("There   was   an   exception");   
pEx->Delete();   
pConnection=NULL;   
return false;
}
}   

}

解决方案 »

  1.   

    GetHttpConnection connects to an HTTP server, and creates and returns a pointer to a CHttpConnection object. It does not perform any specific operation on the server. If you intend to query an HTTP header, for example, you must perform this operation as a separate step. See the classes CHttpConnection and CHttpFile for information about operations you can perform by using a connection to an HTTP server. For information about browsing an HTTP site, see the member function OpenURL. See the article Internet Programming with WinInet for steps in performing common HTTP connection tasks.
    只是构造个对象,不真正链接网络。