CInternetSession session ;
m_pServer=session.GetHttpConnection(strServerName,nPort);
当http服务器没有开启,或者发送的URL错误、非法等,如何判断没有连接上http服务器?

解决方案 »

  1.   

    我用这个
    if (!m_pServer)
    {
    AfxMessageBox("连上服务器");
    }
    else
    {
    AfxMessageBox("没有连上服务器");
    }
    无论http服务器开启还是关闭,都提示"连上服务器".
      

  2.   

    另外,下面的代码无论http服务器开启还是关闭,都不运行AfxMessageBox("555");// check to see if this is a reasonable URLCString strServerName;
    CString strObject;
    INTERNET_PORT nPort;
    DWORD dwServiceType;

    AfxMessageBox(sURL);
    AfxMessageBox("HTTP_URL");

    if (!AfxParseURL(sURL, dwServiceType, strServerName, strObject, nPort) ||
    dwServiceType != INTERNET_SERVICE_HTTP)
    {
    AfxMessageBox("555");

    }
    AfxMessageBox("hhh");
      

  3.   

    To  kingzai() 
    就用我写的那些函数,怎么判断?
      

  4.   

    CString strURL=“http://jasfldkjlskjdfj ld”;
    HINTERNET hConnect = NULL;
    HINTERNET hURL = NULL;
    BOOL bUseProxy;
    CString strProxyName; m_hSession = ::InternetOpen("SiteSnagger",bUseProxy?INTERNET_OPEN_TYPE_PROXY:INTERNET_OPEN_TYPE_PRECONFIG, bUseProxy?(LPCTSTR)strProxyName:(LPCTSTR)NULL,NULL,0);
    // Did it work??
    if(m_hSession != NULL)
    {
    DWORD dwTimeout = 4000;
    ::InternetSetOption(m_hSession,INTERNET_OPTION_CONNECT_TIMEOUT,&dwTimeout,sizeof(dwTimeout));
    }
    else 
    return CInet::BAD_URL; hConnect = ::InternetConnect(m_hSession,strURL,
                                              INTERNET_INVALID_PORT_NUMBER,
                                              strUser,
                                              strPassword,
                                              INTERNET_SERVICE_HTTP,
                                              0,
                                              0) ;
    hURL = ::HttpOpenRequest(hConnect,"GET",strObject,HTTP_VERSION,NULL,szTempX,dwHttpRequestFlags,0) ;
    ::HttpSendRequest(hURL,NULL,0,0,0);
     if(hURL == NULL) 
       //调用失败 说明没有联上:(
      

  5.   

    HINTERNET hSession;
    hSession = InternetOpen("MyApp", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    if (hSession)
    {
        HINTERNET hService;
        hService = InternetOpenUrl(hSession, "http://www.microsoft.com/msj", NULL, 
                                   0, 0, 0);
        if (hService)
        {
            ...
    }
    }
    InternetCloseHandle(hSession);