就是去用VC去得到某个网址的返回值
比如:打开百度,可以访问,得到 http 200
      打开某个不存在的网址,得到 400的错误
      等等 

解决方案 »

  1.   

    打开某个网址后, 获取http头部, 分析返回值
      

  2.   


          // Connect to www.baidu.com.   
          HINTERNET hConnect = InternetConnect(hSession,
                                        "www.baidu.com",
                                        INTERNET_INVALID_PORT_NUMBER,
                                        "",
                                        "",
                                        INTERNET_SERVICE_HTTP,
                                        0,
                                        0);
          
          // Request the file /index.php from the server.
          HINTERNET hUrl = HttpOpenRequest(hConnect,
                                         "GET",
                                         "/index.php",
                                         HTTP_VERSION,
                                         NULL,
                                         0,
                                         INTERNET_FLAG_DONT_CACHE,
                                         0);      // Add request headers
          TCHAR szHeaders[] = "Accept: text/*\r\n";
          BOOL bAddHeaders = HttpAddRequestHeaders(hConnect,
                                      szHeaders,
                                      lstrlen(szHeaders),
                                      HTTP_ADDREQ_FLAG_ADD);      // Send the request.
          BOOL bSendRequest = HttpSendRequest(hUrl, NULL, 0, 0, 0);      if(hUrl == NULL)
          {
                  printf("InternetOpenUrl Error......\n");
                  InternetCloseHandle(hSession);
                  return 0;
          }
          
          BOOL bRet = HttpQueryInfo(hUrl, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &dwStatusCode, &dwSizeOfStatusCode, NULL);
          if(!bRet)
          {
                 printf("HttpQueryInfo Error......\n");
                 return 0;
          }
          
          // Key point
          if(404 == dwStatusCode)
          {
                 InternetCloseHandle(hUrl) ;
                 InternetCloseHandle(hSession) ;
                 return 0;
          }