当前位置: 首页>>代码示例>>C++>>正文


C++ CInternetSession::OpenURL方法代码示例

本文整理汇总了C++中CInternetSession::OpenURL方法的典型用法代码示例。如果您正苦于以下问题:C++ CInternetSession::OpenURL方法的具体用法?C++ CInternetSession::OpenURL怎么用?C++ CInternetSession::OpenURL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CInternetSession的用法示例。


在下文中一共展示了CInternetSession::OpenURL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

int CXCCRA2MapUpdaterApp::download_update(string link, string fname)
{
	int error = 0;
	CInternetSession is;
	CHttpFile* f = reinterpret_cast<CHttpFile*>(is.OpenURL(link.c_str(), INTERNET_FLAG_TRANSFER_BINARY));
	if (!f)
		error = 1;
	else 
	{
		Cvirtual_file h;
		DWORD status;
		if (!f->QueryInfoStatusCode(status))
			error = 2;
		else if (status != 200)
			error = 3;
		else
		{
			int total_size = f->Seek(0, CFile::end);
			f->Seek(0, CFile::begin);
			Cdownload_dlg dlg;
			dlg.set(link, fname, total_size);
			dlg.Create(Cdownload_dlg::IDD, NULL);
			dlg.EnableWindow(false);
			Cvirtual_binary t;
			while (!error)
			{
				int cb_p = min<int>(f->GetLength(), 1 << 10);
				if (!cb_p)
					break;
				f->Read(t.write_start(cb_p), cb_p);
				h.write(t);
				dlg.set_size(h.size());
				dlg.UpdateWindow();
			}
			h.compact();
			Cxif_key k;
			if (k.load_key(h.data(), h.size()))
				error = 5;
			else
			{
				for (t_xif_key_map::const_iterator ki = k.m_keys.begin(); ki != k.m_keys.end(); ki++)
				{
					if (error)
						break;
					const Cxif_key& l = ki->second;
					string fext = boost::to_lower_copy(Cfname(l.get_value_string(vi_fname)).get_fext());
					if (fext != ".mmx"
						&& (fext != ".yro") || !Cfname(xcc_dirs::get_exe(game_ra2_yr)).exists())
						continue;
					if (file32_write(Cfname(fname).get_path() + l.get_value_string(vi_fname), l.get_value(vi_fdata).get_data(), l.get_value(vi_fdata).get_size()))
						error = 6;
				}
			}
			dlg.DestroyWindow();
		}
		f->Close();
	}
	return error;
}
开发者ID:ChangerR,项目名称:xcc,代码行数:59,代码来源:XCC+RA2+Map+Updater.cpp

示例2:

void C51JobWebPost::TestProxy()
{
	CInternetSession session;

	CHttpFile *file = NULL;   



	INTERNET_PROXY_INFO proxyinfo;

	proxyinfo.dwAccessType = INTERNET_OPEN_TYPE_PROXY;

	proxyinfo.lpszProxy ="122.205.95.14:80";

	proxyinfo.lpszProxyBypass = NULL;

	
	session.SetOption(INTERNET_OPTION_PROXY,(LPVOID)&proxyinfo,
		sizeof(INTERNET_PROXY_INFO));
	
	try{

		file = (CHttpFile*)session.OpenURL("http://www.ip138.com/ip2city.asp",1,
			INTERNET_FLAG_TRANSFER_ASCII|INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE);		

	}catch(CInternetException * m_pException){

		file = NULL;

		m_pException->m_dwError;

		m_pException->Delete();

		session.Close();

		AfxMessageBox("CInternetException");

		return;

	}

	CString strLine;
	CString strResult = "";
	if(file != NULL){

		while(file->ReadString(strLine) != NULL){

			strResult += strLine;

		}

	}else{
		AfxMessageBox("fail");
	}
	file->Close();
	session.Close();
}
开发者ID:wyrover,项目名称:myhistoryprojects,代码行数:57,代码来源:51JobWebPost.cpp

示例3: ThreadProc

DWORD CAsyncUrlReader::ThreadProc()
{
    AfxSocketInit(nullptr);

    DWORD cmd = GetRequest();
    if (cmd != CMD_INIT) {
        Reply((DWORD)E_FAIL);
        return (DWORD) - 1;
    }

    try {
        CInternetSession is;
        CAutoPtr<CStdioFile> fin(is.OpenURL(m_url, 1, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_CACHE_WRITE));

        TCHAR path[MAX_PATH], fn[MAX_PATH];
        CFile fout;
        if (GetTempPath(MAX_PATH, path) && GetTempFileName(path, _T("mpc_http"), 0, fn)
                && fout.Open(fn, modeCreate | modeWrite | shareDenyWrite | typeBinary)) {
            m_fn = fn;

            char buff[1024];
            int len = fin->Read(buff, sizeof(buff));
            if (len > 0) {
                fout.Write(buff, len);
            }

            Reply(S_OK);

            while (!CheckRequest(&cmd)) {
                int len2 = fin->Read(buff, sizeof(buff));
                if (len2 > 0) {
                    fout.Write(buff, len2);
                }
            }
        } else {
            Reply((DWORD)E_FAIL);
        }

        fin->Close(); // must close it because the destructor doesn't seem to do it and we will get an exception when "is" is destroying
    } catch (CInternetException* ie) {
        ie->Delete();
        Reply((DWORD)E_FAIL);
    }

    //

    cmd = GetRequest();
    ASSERT(cmd == CMD_EXIT);
    Reply(S_OK);

    //

    m_hThread = nullptr;

    return S_OK;
}
开发者ID:slavanap,项目名称:ssifSource,代码行数:56,代码来源:AsyncReader.cpp

示例4: GetUrlText

/*-----------------------------------------------------------------------------
	Get a string response from the given url (used for querying the EC2 instance config)
-----------------------------------------------------------------------------*/
bool CurlBlastDlg::GetUrlText(CString url, CString &response)
{
    bool ret = false;

    try
    {
        // set up the session
        CInternetSession * session = new CInternetSession();
        if( session )
        {
            DWORD timeout = 10000;
            session->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, &timeout, sizeof(timeout), 0);
            session->SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT, &timeout, sizeof(timeout), 0);
            session->SetOption(INTERNET_OPTION_SEND_TIMEOUT, &timeout, sizeof(timeout), 0);
            session->SetOption(INTERNET_OPTION_DATA_SEND_TIMEOUT, &timeout, sizeof(timeout), 0);
            session->SetOption(INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, &timeout, sizeof(timeout), 0);

            CInternetFile * file = (CInternetFile *)session->OpenURL(url);
            if( file )
            {
                char buff[4097];
                DWORD len = sizeof(buff) - 1;
                UINT bytes = 0;
                do
                {
                    bytes = file->Read(buff, len);
                    if( bytes )
                    {
                        ret = true;
                        buff[bytes] = 0;	// NULL-terminate it
                        response += CA2T(buff);
                    }
                } while( bytes );

                file->Close();
                delete file;
            }

            session->Close();
            delete session;
        }
    }
    catch(CInternetException * e)
    {
        e->Delete();
    }
    catch(...)
    {
    }

    log.Trace(_T("EC2 '%s' -> '%s'"), (LPCTSTR)url, (LPCTSTR)response);

    return ret;
}
开发者ID:ceeaspb,项目名称:webpagetest,代码行数:57,代码来源:urlBlastDlg.cpp

示例5:

int CXCCRA2MapUpdaterApp::update()
{
	int error = 0;
	try
	{
		CWaitCursor wait;
		CInternetSession is;
		CHttpFile* f = reinterpret_cast<CHttpFile*>(is.OpenURL("http://xccu.sourceforge.net/ra2_maps/official.ucf"));
		if (!f)
			error = 1;
		else
		{
			string s;
			while (1)
			{
				int cb_p = f->GetLength();
				if (!cb_p)
					break;
				char* p = new char[cb_p + 1];
				f->Read(p, cb_p);
				p[cb_p] = 0;
				s += p;
				delete[] p;
			}
			f->Close();
			Cvirtual_tfile f;
			f.load_data(Cvirtual_binary(s.c_str(), s.length()));
			while (!f.eof())
			{
				Cmulti_line l = f.read_line();
				Cfname fname = xcc_dirs::get_dir(game_ra2) + l.get_next_line('=') + ".mmx";
				if (!fname.exists())
				{
					string version = l.get_next_line(',');
					string link = l.get_next_line(',');
					error = download_update(link, fname);
					if (error)
					{
						delete_file(fname);
						MessageBox(NULL, "Error retrieving update.", NULL, MB_ICONERROR);
						error = 0;
					}
				}
			}
		}
	}
	catch (CInternetException*)
	{
		error = 1;
	}
	if (error)
		MessageBox(NULL, "Error querying for update.", NULL, MB_ICONERROR);
	return error;
}
开发者ID:ChangerR,项目名称:xcc,代码行数:54,代码来源:XCC+RA2+Map+Updater.cpp

示例6: DownloadFile

BOOL CAutoUpdateDlg::DownloadFile(LPCTSTR lpURL,LPCTSTR lpDestFile)
{
	CFile cUdpFile; 
	if(!cUdpFile.Open(lpDestFile,CFile::modeCreate|CFile::modeWrite|CFile::typeBinary|CFile::shareDenyWrite))
		return FALSE;
	BOOL bResult = FALSE;
	CInternetSession sessionDownload;
	try
	{
		CHttpFile* pFile = (CHttpFile*)sessionDownload.OpenURL(lpURL,1,INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE);
		CString   query = _T("");
		pFile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH,query);
		long file_len=_ttol(query);
		m_dwTotalSize = file_len;
		PostMessage(WM_POSMESSAGE,0,0);
		DWORD dwStatus;
		if (pFile->QueryInfoStatusCode(dwStatus))
		{
			if (dwStatus == 200)
			{
				pFile->SetReadBufferSize(10240);
				if (TRUE)
				{
					DWORD dwLen = 0;
					char buf[BLOCKSIZE];
					while (TRUE)
					{
						DWORD dwTemp = pFile->Read(buf,BLOCKSIZE);
						if (dwTemp)
						{
							cUdpFile.Write(buf,dwTemp);
						}
						m_dwDownloadedSize += dwTemp;
						PostMessage(WM_POSMESSAGE,0,0);
						if (dwTemp < BLOCKSIZE)
						{
							break;
						}
					}
				}
			}
		}
		pFile->Close();
		bResult = TRUE;
	}
	catch(CInternetException* pException)
	{
		pException->Delete();
		return bResult;
	}
	sessionDownload.Close();
	cUdpFile.Close();
	return bResult;
}
开发者ID:shzhqiu,项目名称:weibo,代码行数:54,代码来源:AutoUpdateDlg.cpp

示例7: LoadUpdate

DWORD WINAPI LoadUpdate (LPVOID param)
{
  CUpdateDlg* dlg = (CUpdateDlg*) param;

  if (dlg->autoCheck)
    UpdateVersion (NULL);

  char buf[2048];
  sprintf (buf, "Current version: %s\r\n"
                "Last version: %s\r\n",
                formatVersion (curVersion),
                formatVersion (lastVersion));
  dlg->SetDlgItemText (IDC_BUFFER, buf);

  if (curVersion < lastVersion)
  {
    CString log = buf;
    log += "\r\nLoading changelog...";
    dlg->SetDlgItemText (IDC_BUFFER, log);
    try
    {
      CInternetSession inet;
      CInternetFile* file = dynamic_cast<CInternetFile*> (inet.OpenURL (logURL));
      log = buf;
      log += "\r\nChangelog:\r\n";
      if (file != NULL)
      {
        while (file->ReadString (buf, sizeof buf - 5))
        {
          if (buf[0] == '*' && buf[1] == '*')
          {
            unsigned int ver = parseVersion (buf + 2);
            if (ver != 0 && ver <= curVersion)
              break;
          }
          log += buf;
        }
        log.Replace ("\n", "\r\n");
        dlg->SetDlgItemText (IDC_BUFFER, log);
        delete file;
      }
      else
        lastVersion = 0;
    }
    catch (CInternetException*)
    {
    }
  }

  return 0;
}
开发者ID:liyonghelpme,项目名称:dota-replay-manager,代码行数:51,代码来源:UpdateDlg.cpp

示例8: IsReachableURL

bool CUtil::IsReachableURL(CString sURL)
{
	CInternetSession Session;
	CHttpFile * pFile;
	try
	{
		pFile = (CHttpFile *) Session.OpenURL(sURL);
	}
	catch (CException * e)
	{
		e->Delete();
		pFile = NULL;
	}
	return (pFile != NULL);
}
开发者ID:bluejoe2008,项目名称:TaskedPortDemo,代码行数:15,代码来源:Util.cpp

示例9: VersionCheckerThread

void CVersionChecker::VersionCheckerThread()
{
	UINT totalBytesRead = 0;
	// The version tag usually shows up about 20,000 bytes in.
	char buffer[40000];
	try
	{
		CInternetSession	MySession;
		const wchar_t* const url = L"https://github.com/google/UIforETW/releases/";
		std::unique_ptr<CStdioFile> webFile(MySession.OpenURL(url));
		// Read into the buffer -- set the maximum to one less than the length
		// of the buffer.
		while (totalBytesRead < sizeof(buffer) - 1)
		{
			const UINT bytesRead = webFile->Read(buffer + totalBytesRead, sizeof(buffer) - 1 - totalBytesRead);
			if (!bytesRead)
				break;
			totalBytesRead += bytesRead;
		}
		webFile->Close();
	}
	catch (...)
	{
	}
	// Null terminate the buffer.
	buffer[totalBytesRead] = 0;
	const char* const marker = "<a href=\"/google/UIforETW/tree/";
	char* version_string = strstr(buffer, marker);
	if (version_string)
	{
		version_string += strlen(marker);
		if (strlen(version_string) > 4)
		{
			// String is something like: "v1.32\?..." and we want to cut off after
			// v1.32
			version_string[5] = 0;
			PackagedFloatVersion newVersion;
			newVersion.u = 0;
			if (sscanf_s(version_string, "v%f", &newVersion.f) == 1)
			{
				if (newVersion.f > kCurrentVersion)
				{
					pWindow_->PostMessage(WM_NEWVERSIONAVAILABLE, newVersion.u);
				}
			}
		}
	}
}
开发者ID:curtnichols,项目名称:UIforETW,代码行数:48,代码来源:VersionChecker.cpp

示例10: DownLoadFile

bool CDlgView::DownLoadFile(const string&UrpPath ,const string& strFilePath)
{
    CInternetSession session;
    std::string strHtml;

    try
    {
        CHttpFile* pfile = (CHttpFile*)session.OpenURL(UrpPath.c_str(),1,INTERNET_FLAG_TRANSFER_ASCII|INTERNET_FLAG_RELOAD,NULL,0);

        DWORD dwStatusCode;
        pfile->QueryInfoStatusCode(dwStatusCode);
        if(dwStatusCode == HTTP_STATUS_OK)
        {
            char strBuff[1025] = {0};
            while ((pfile->Read((void*)strBuff, 1024)) > 0)
            {
                strHtml += strBuff;
            }
        }
        else
        {
            return false;
        }

        pfile->Close();
        delete pfile;
        session.Close();
    }
    catch (CException* e)
    {
        e;//消除警告
        return false;
    }

    if (!strHtml.empty())
    {
        ofstream outfile(strFilePath);
        if (!outfile.is_open())
        {
            return false;
        }
        outfile<<strHtml;
        outfile.close();
    }
    return true;
}
开发者ID:SoyPay,项目名称:DacrsUI,代码行数:46,代码来源:DlgView.cpp

示例11: isUpdateAvailable

Update_Status UpdateChecker::isUpdateAvailable(const Version& currentVersion)
{
	Update_Status updateAvailable = UPDATER_LATEST_STABLE;

	try {
		CInternetSession internet;
		CHttpFile* versionFile = (CHttpFile*) internet.OpenURL(versionFileURL,
															   1,
															   INTERNET_FLAG_TRANSFER_ASCII | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD,
															   NULL,
															   0);

		if (versionFile) {
			CString latestVersionStr;
			char buffer[101];
			UINT br = 0;

			while ((br = versionFile->Read(buffer, 50)) > 0) {
				buffer[br] = '\0';
				latestVersionStr += buffer;
			}

			if (!parseVersion(latestVersionStr)) {
				updateAvailable = UPDATER_ERROR;
			} else {
				int comp = compareVersion(currentVersion, latestVersion);

				if (comp < 0) {
					updateAvailable = UPDATER_UPDATE_AVAILABLE;
				} else if (comp > 0) {
					updateAvailable = UPDATER_NEWER_VERSION;
				}
			}

			delete versionFile;
		} else {
			updateAvailable = UPDATER_ERROR;
		}
	} catch (CInternetException* pEx) {
		updateAvailable = UPDATER_ERROR;
		pEx->Delete();
	}

	return updateAvailable;
}
开发者ID:Samangan,项目名称:mpc-hc,代码行数:45,代码来源:UpdateChecker.cpp

示例12: GetSourceHtml

bool CWebpageHandler::GetSourceHtml(CString theUrl,CString fileName)
{
    CInternetSession session;
	CHttpFile *file = NULL; 
	CString strURL = theUrl;
	CString strHtml = _T("");   //存放网页数据 

	try{
		   file = (CHttpFile*)session.OpenURL(strURL);

	}catch(CInternetException * m_pException){
		   file = NULL;
		   m_pException->m_dwError;
		   m_pException->Delete();
		   session.Close();

		   MessageBox(_T("网络连接失败!"));
		   return false;
	}

	CString strLine;
	if(file != NULL){
		   while(file->ReadString(strLine) != NULL){
		   strHtml += strLine;
		   }
 	}else{
		MessageBox(_T("读取网络数据失败!"));
		return false;
	}
 
	CFile file0(fileName, CFile::modeCreate|CFile::modeWrite);
	int len = strHtml.GetLength()*2;
	file0.Write(strHtml, len);
	session.Close();
	file->Close();
	file0.Close();
	delete file;
	file = NULL;

	m_htmlStr = strHtml;
	m_url = theUrl;
	return true;
}
开发者ID:ElvisJazz,项目名称:DesktopCalendar,代码行数:43,代码来源:WebpageHandler.cpp

示例13: OpenUrl

bool OpenUrl(CInternetSession& is, CString url, CStringA& str)
{
	str.Empty();

	try {
		CAutoPtr<CStdioFile> f(is.OpenURL(url, 1, INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_EXISTING_CONNECT));

		char buff[1024];
		for (int len; (len = f->Read(buff, sizeof(buff))) > 0; str += CStringA(buff, len)) {
			;
		}

		f->Close(); // must close it because the destructor doesn't seem to do it and we will get an exception when "is" is destroying
	} catch (CInternetException* ie) {
		ie->Delete();
		return false;
	}

	return true;
}
开发者ID:Samangan,项目名称:mpc-hc,代码行数:20,代码来源:ISDb.cpp

示例14: UpdateVersion

DWORD WINAPI UpdateVersion (LPVOID param)
{
  try
  {
    CInternetSession inet;
    CInternetFile* file = dynamic_cast<CInternetFile*> (inet.OpenURL (versionURL));
    char buf[256];
    if (file != NULL)
    {
      lastVersion = parseVersion (file->ReadString (buf, 255));
      delete file;
    }
    else
      lastVersion = 0;
  }
  catch (CInternetException*)
  {
  }
  return 0;
}
开发者ID:liyonghelpme,项目名称:dota-replay-manager,代码行数:20,代码来源:UpdateDlg.cpp

示例15: GetHtmlSource

string GetHtmlSource(CString strURL)
{
	CInternetSession session;
	CHttpFile *file = NULL; 

	CString strHtml = _T(""); //存放网页数据
	file =(CHttpFile*)session.OpenURL(strURL,1,INTERNET_FLAG_RELOAD);
 
	//CString strLine;
	char sRecived[1024];
	if(file != NULL) {
	while(file->ReadString((LPTSTR)sRecived,1024)!=NULL) {
	strHtml += sRecived; }
 }
	session.Close();
	if(file!=NULL) file->Close();
	delete file; file = NULL;

	string html =  CT2A(strHtml.GetBuffer(0));
	return html;
}
开发者ID:linchuming,项目名称:sophomore,代码行数:21,代码来源:xkDlg.cpp


注:本文中的CInternetSession::OpenURL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。