导航

<2005年1月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345

随笔分类

随笔档案

文章档案

相册

2005年1月14日

BOOL ExistHttpFile(LPCTSTR lpHttpFile)
{
 CInternetSession session("Client",PRE_CONFIG_INTERNET_ACCESS);
 CHttpConnection* pServer = NULL;
 CHttpFile* pFile = NULL;
 CString strServerName(""),strObject("");
 INTERNET_PORT nPort;
 DWORD dwServiceType;
 BOOL bRight=FALSE;
 try
 {
  if (!AfxParseURL(lpHttpFile, dwServiceType, strServerName, strObject, nPort) ||
            dwServiceType != INTERNET_SERVICE_HTTP)    throw(1);
  pServer = session.GetHttpConnection(strServerName, nPort);
  pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,
          strObject, NULL, 1, NULL, NULL, 
          INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT);
  pFile->AddRequestHeaders("Client");
  pFile->SendRequest();
  DWORD dwRet;
  pFile->QueryInfoStatusCode(dwRet);
  if (dwRet == HTTP_STATUS_DENIED) throw(1);
  CString strNewLocation("");
  pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation);
  // 是否重定向
  if (dwRet == HTTP_STATUS_MOVED ||
   dwRet == HTTP_STATUS_REDIRECT ||
   dwRet == HTTP_STATUS_REDIRECT_METHOD)
         throw(1);
  if(strNewLocation.Find("200 OK") != -1)             bRight=TRUE;
  else if(strNewLocation.Find("Content-Type:") !=-1 ) bRight=TRUE;
  pFile->Close();
  pServer->Close();
 }
 catch(...)
 {
    bRight=FALSE;
 }
 if(pFile)    delete pFile;
 if(pServer)  delete pServer;
 session.Close();

 return bRight;
}
发表于 2005-01-14 12:01 杨老师的茅屋 阅读(1313) | 评论 (1)编辑 收藏

统计