'抛出错误12005的CInternetException'

时间:2016-02-10 20:40:43

标签: c++ post sharepoint mfc

我一直“因错误12005而抛出CInternetException”

根据this,我的网址无效。但是,URL是正确的,我可以访问此SharePoint站点。

我不确定有什么问题,这是我的代码:

(错误发生在pFile->SendRequest();

void CUserPassDiag::Connect(){
    CInternetSession session(_T("My Session"));
    CHttpConnection* pServer = NULL;
    CHttpFile* pFile = NULL;
    try
    {
        CString strServerName = _T("http://collaboration.unc.ca");
        CString headers = "Content-Type: application/x-www-form-urlencoded\r\n";
        headers += "Host: xcollaboration.pwc.ca\r\n";
        headers += "Method: POST\r\n";
        headers += "Pragma: no-cache\r\n";
        headers += "Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, *//*r\n";

        CString szHeaders = _T("%s",headers);
        //To Be Send    
        CString strFormData  = _T("action=setCameraSetting&videoOverlay.useTimestamp=1&videoOverlay.useText=1&videoOverlay.displayString=12.12-77.32");

        DWORD dwRet;
        CString strObject = _T("/team/T5342DFG/SitePages/UNCHome.aspx");
        pServer = session.GetHttpConnection(strServerName, INTERNET_DEFAULT_HTTP_PORT, _T(""), _T(""));
        pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST, strObject);
        pFile->AddRequestHeaders(szHeaders);
        pFile->SendRequest();
        pFile->QueryInfoStatusCode(dwRet);
        TRACE("%d",dwRet);
        delete pFile;
        delete pServer;

    }catch(CInternetException* e){
        TCHAR sz[1024];
        e->GetErrorMessage(sz,1024);
        _tprintf_s(_T("ERROR!  %s\n"), sz);
        e->Delete();
    }
  session.Close();

}

1 个答案:

答案 0 :(得分:0)

服务器名称(strServerName)不应包含http://前缀 - 它应该只是服务器的域名(或IP地址)。