繁体   English   中英

CinternetSession:连接时的奇怪行为

[英]CinternetSession: Strange behavior when connecting

应该将其添加到项目中,检查代理服务器的有效性。 该算法的工作很简单:1.我正在尝试通过代理连接到特定服务器。 2.我得到页面内容(地址)。 3.直接连接到同一服务器。 4.如果它们匹配代理,则它们的地址不是匿名的。

但是由于某种原因,程序先连接到代理后,再试图通过另一个代理或直接建立连接是不成功的。 当我读取地址时,您总是会得到第一个代理的地址。 尝试运行测试一段时间后,检查所有内容将开始正常工作。但是足以重新启动Windows并重新开始。

我究竟做错了什么? 项目http://dl.dropbox.com/u/10669949/work/internet_site.zip

CString CDataSender::GetNotDirect(CString proxy)
{
    try
    {
        auto_ptr<CString> proxyip(new CString);
        CString page ="/ip.php";
        CString host="176.65.165.57";
        if (proxy.IsEmpty()) return "";

        auto_ptr<CInternetSession> iProxy (new CInternetSession("Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.8.131 Version/11.11",1,INTERNET_OPEN_TYPE_PROXY,proxy));
        auto_ptr<CHttpConnection> pH(iProxy->GetHttpConnection(host,INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_PRAGMA_NOCACHE,80));
        auto_ptr<CHttpFile> pF(pH->OpenRequest("GET",page));
        pF->SendRequest();
        pF->ReadString(*proxyip);
        iProxy->Close();
        pH->Close();
        pF->Close();
        return *proxyip;
    }
    catch(CInternetException *pEx)
    {
        cout<<pEx->m_dwError<<endl;
        return "";
    }
}


CString CDataSender::GetDirect()
{       
    try
    {
        auto_ptr<CString> directip(new CString);
        int nCount=0;

        CString page ="/ip.php"; 
        CString host="176.65.165.57";   
        auto_ptr<CInternetSession> iDirect(new CInternetSession (/*"Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.8.131 Version/11.11"*/"",1,INTERNET_OPEN_TYPE_DIRECT));
        auto_ptr<CHttpConnection> pH(iDirect->GetHttpConnection(host,INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_PRAGMA_NOCACHE,80));
        auto_ptr<CHttpFile> pF(pH->OpenRequest("GET",page));
        pF->SendRequest();
        pF->ReadString(*directip);
        iDirect->Close();
        //////////////////////////////////////////////////////////////////////////
        pH->Close();
        pF->Close();
        return *directip;
    }
    catch(CInternetException *pEx)
    {       
        cout<<pEx->m_dwError<<endl;
        return "";
    }

}



int CDataSender::CheckProxy(CString proxy)
{       
    CString directip="",proxyip="";
    proxyip.Empty();directip.Empty();
    proxyip=GetNotDirect(proxy);
    if(proxyip!="")
        directip=GetDirect();
    else
        return -1;
    cout<<"Direct: "<<directip<<endl;
    cout<<"Proxy: "<<proxyip<<endl;
    if ((proxyip!="")&&(directip!="")&&(proxyip.Find("html")==-1)&&/*(proxyip.GetLength()<16) &&*/(proxyip.Find(directip)==-1) /*|| proxyip=="1.1.1.1"*/) 
    {
        return 1;
    }
    return -1;
}

尝试使用套接字而不是WinInet

解决了问题。 添加了适当的标志。

auto_ptr<CHttpConnection> pH(iDirect->GetHttpConnection(host,INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE|INTERNET_IDENTITY_FLAG_CLEAR_CONTENT|INTERNET_IDENTITY_FLAG_CLEAR_DATA|INTERNET_IDENTITY_FLAG_CLEAR_COOKIES,80));
    auto_ptr<CHttpFile> pF(pH->OpenRequest("GET",page,NULL,1,NULL,NULL,INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE|INTERNET_IDENTITY_FLAG_CLEAR_CONTENT|INTERNET_IDENTITY_FLAG_CLEAR_DATA|INTERNET_IDENTITY_FLAG_CLEAR_COOKIES));

同样,用于另一个功能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM