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


C++ InternetReadFile函数代码示例

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


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

示例1: sprintf

int P3DUpdateManager::CheckForUpdates(const char* bugServer)
{
    if (!CVe_updates.GetBool()) return false;

    char *query = new char[128];
    char *outResult = new char[1024];

    sprintf(query, "%s/?a=d&v1=%d&v2=%d&v3=%d&v4=%d", bugServer, P3DVER_1, P3DVER_2, P3DVER_3, P3DVER_4);
    //do
    //{
    HINTERNET hInet = InternetOpen("P3DUP", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    HINTERNET hFile = InternetOpenUrl(hInet, query, NULL, 0, INTERNET_FLAG_RELOAD, 0);
    if (!hInet || !hFile) return 0;
    DWORD size;
    outResult[0]=0;
    if (!InternetReadFile(hFile, outResult, 1023, &size))
        return 0;
    outResult[size]=0;
    if (!InternetCloseHandle(hFile)) return 0;
    if (!InternetCloseHandle(hInet)) return 0;
    //}while(outResult[0]==0);

    // zjisti pocet updatu
    unsigned int lastPos=0;
    for (unsigned int i=0; i<strlen(outResult); i++)
    {
        if (outResult[i]==';')
        {
            char* tmpChar = new char[i-lastPos+1];
            strncpy(tmpChar, &outResult[lastPos], i-lastPos);
            tmpChar[i-lastPos]=0;
            m_pUpdLinks.push_back(tmpChar);

            lastPos = i+1;
            m_nUpdates++;
        }
    }

    delete[] query;
    delete[] outResult;

    return m_nUpdates;
    return 0;
}
开发者ID:k3a,项目名称:Panther3D-1,代码行数:44,代码来源:updater.cpp

示例2: DownloadToMemory

LPBYTE DownloadToMemory(IN LPCTSTR lpszURL, OUT PDWORD_PTR lpSize)
{
	LPBYTE lpszReturn = 0;
	*lpSize = 0;
	const HINTERNET hSession = InternetOpen(TEXT("GetGitHubRepositoryList"), INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, INTERNET_FLAG_NO_COOKIES);
	if (hSession)
	{
		URL_COMPONENTS uc = { 0 };
		TCHAR HostName[MAX_PATH];
		TCHAR UrlPath[MAX_PATH];
		uc.dwStructSize = sizeof(uc);
		uc.lpszHostName = HostName;
		uc.lpszUrlPath = UrlPath;
		uc.dwHostNameLength = MAX_PATH;
		uc.dwUrlPathLength = MAX_PATH;
		InternetCrackUrl(lpszURL, 0, 0, &uc);
		const HINTERNET hConnection = InternetConnect(hSession, HostName, INTERNET_DEFAULT_HTTPS_PORT, 0, 0, INTERNET_SERVICE_HTTP, 0, 0);
		if (hConnection)
		{
			const HINTERNET hRequest = HttpOpenRequest(hConnection, TEXT("GET"), UrlPath, 0, 0, 0, INTERNET_FLAG_SECURE | INTERNET_FLAG_RELOAD, 0);
			if (hRequest)
			{
				HttpSendRequest(hRequest, 0, 0, 0, 0);
				lpszReturn = (LPBYTE)GlobalAlloc(GMEM_FIXED, 1);
				DWORD dwRead;
				static BYTE szBuf[1024 * 4];
				LPBYTE lpTmp;
				for (;;)
				{
					if (!InternetReadFile(hRequest, szBuf, (DWORD)sizeof(szBuf), &dwRead) || !dwRead) break;
					lpTmp = (LPBYTE)GlobalReAlloc(lpszReturn, (SIZE_T)(*lpSize + dwRead), GMEM_MOVEABLE);
					if (lpTmp == NULL) break;
					lpszReturn = lpTmp;
					CopyMemory(lpszReturn + *lpSize, szBuf, dwRead);
					*lpSize += dwRead;
				}
				InternetCloseHandle(hRequest);
			}
			InternetCloseHandle(hConnection);
		}
		InternetCloseHandle(hSession);
	}
	return lpszReturn;
}
开发者ID:kenjinote,项目名称:GetGitHubRepositoryList,代码行数:44,代码来源:Source.cpp

示例3: _T

bool CHTTPParser::readString(CString& rString, HINTERNET hFile)
{
	const DWORD dwBufferSize = 1024;
	DWORD dwRead = 0;
	CHAR svBuffer[dwBufferSize];

	rString = _T("");

	ZeroMemory(svBuffer, dwBufferSize);
	
	while(InternetReadFile(hFile, svBuffer, dwBufferSize, &dwRead) && dwRead != 0)
	{
		CA2T pszBuffer((LPCSTR)svBuffer);
		
		rString.Append(pszBuffer);
	}

	return true;
}
开发者ID:openxtra,项目名称:hotspot-sdk,代码行数:19,代码来源:HTTPParser.cpp

示例4: http_get

bool http_get(LPCTSTR szURL, LPCTSTR szFileName)
{
    HINTERNET	hInternet, hUrl;
    HANDLE		hFile;
    char		buffer[1024];
    DWORD		dwBytesRead = 0;
    DWORD		dwBytesWritten = 0;
    BOOL		bIsFirstPacket = true;
    BOOL		bRet = true;
    hInternet = InternetOpen("Mozilla/4.0 (compatible)", INTERNET_OPEN_TYPE_PRECONFIG, NULL,INTERNET_INVALID_PORT_NUMBER,0);
    if (hInternet == NULL)
        return false;

    hUrl = InternetOpenUrl(hInternet, szURL, NULL, 0, INTERNET_FLAG_RELOAD, 0);
    if (hUrl == NULL)
        return false;

    hFile = CreateFile(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);

    if (hFile != INVALID_HANDLE_VALUE)
    {
        do
        {
            memset(buffer, 0, sizeof(buffer));
            InternetReadFile(hUrl, buffer, sizeof(buffer), &dwBytesRead);
            // 由判断第一个数据包是不是有效的PE文件
            if (bIsFirstPacket && ((PIMAGE_DOS_HEADER)buffer)->e_magic != IMAGE_DOS_SIGNATURE)
            {
                bRet = false;
                break;
            }
            bIsFirstPacket = false;

            WriteFile(hFile, buffer, dwBytesRead, &dwBytesWritten, NULL);
        } while(dwBytesRead > 0);
        CloseHandle(hFile);
    }

    InternetCloseHandle(hUrl);
    InternetCloseHandle(hInternet);

    return bRet;
}
开发者ID:xinba123,项目名称:shell,代码行数:43,代码来源:until.cpp

示例5: get_url_string

bool get_url_string(wstring url, string &out)
{
	char buffer[HTTP_BUFFER_LEN];//下载文件的缓冲区
	DWORD bytes_read = 1;//下载的字节数
	bool getre = false;
	out = "";

	if(url.length() < 6)
		return false;

	//打开一个internet连接
	HINTERNET internet=InternetOpen(_T("User-Agent"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL);
	if(!internet)
		return false;

	DWORD timeout = 5000;
	InternetSetOption(internet, INTERNET_OPTION_CONNECT_TIMEOUT, &timeout, sizeof(DWORD));

	timeout = 10000;
	InternetSetOption(internet, INTERNET_OPTION_SEND_TIMEOUT, &timeout, sizeof(DWORD));

	//打开一个http url地址
	HINTERNET file_handle=InternetOpenUrl(internet, url.c_str(), NULL, 0, INTERNET_FLAG_RELOAD, 0);

	if(file_handle) {
		//从url地址中读取文件内容到缓冲区buffer
		BOOL b = 0;
		int readbyte = 0;
		while(bytes_read > 0) {
			b = InternetReadFile(file_handle, buffer, 512 , &bytes_read);
			if(!b)
				break;
			readbyte += bytes_read;
			buffer[bytes_read] = 0;
			out += buffer;
		}
		getre = true;
	}
	//关闭连接
	InternetCloseHandle(internet);

	return getre;
}
开发者ID:william0wang,项目名称:meditor,代码行数:43,代码来源:shared.cpp

示例6: FetchMore

int HttpSnaffle::FetchMore(std::ostream& out)
{
    // Find out how much there is to download
    DWORD dwSize;
    if (!InternetQueryDataAvailable(myRequest, &dwSize, 0, 0))
        return -1;

	if (!dwSize)
		return 0;

    // Make sure buffer is big enough
    myBuffer.resize(dwSize);

    // Read the data
    DWORD dwDownloaded;
    if (!InternetReadFile(myRequest, (LPVOID)&myBuffer[0], dwSize, &dwDownloaded))
        return -1;

    // See if we're done
    if (dwDownloaded == 0)
    {
        int statusCode = -1;
        DWORD size = sizeof(statusCode);
        DWORD index = 0;
        if (!HttpQueryInfo(myRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &statusCode, &size, &index))
            return -1;

        if (statusCode != HTTP_STATUS_OK)
            return -1;

        InternetCloseHandle(myRequest);
        myRequest = NULL;

        return 0;
    }

    // Write it out to a file
    // std::cout << "Read in " << dwDownloaded << " bytes" << std::endl;
    out.write(&myBuffer[0], dwDownloaded);

    return dwDownloaded;
}
开发者ID:pampersrocker,项目名称:G-CVSNT,代码行数:42,代码来源:HttpSnaffle.cpp

示例7: InternetReadFile

void CNetRequestImpl::readInetFile( HINTERNET hRequest, CNetDataImpl* pNetData )
{
    DWORD dwBufSize = 4096;
    char* pBuf = (char*)malloc(dwBufSize);
    DWORD dwBytesRead = 0;
    BOOL bRead = FALSE;
    do
    {
        bRead = InternetReadFile(hRequest, pBuf, dwBufSize, &dwBytesRead);
        if ( bRead )
        {
            if (dwBytesRead > 0)
                pNetData->getRawData().append(pBuf,dwBytesRead);

            pNetData->setValid(true);
        }
    }while(bRead && dwBytesRead > 0);

    free(pBuf);
}
开发者ID:ravitheja22,项目名称:rhodes,代码行数:20,代码来源:NetRequestImpl.cpp

示例8: HttpGetUrl

_bstr_t HttpGetUrl(const _bstr_t& url)
{
	_bstr_t retval;

	HINTERNET hSession = InternetOpen(_T("HttpGet"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

	if (hSession)
	{
		bool isSsl = false;
		//const char* u = static_cast<const char*>(url);

		HINTERNET hFile = InternetOpenUrl(hSession, url, NULL, 0, 0, 0);
		
		if (hFile)
		{
			DWORD bytesAvailable = 0;
			
			if (InternetQueryDataAvailable(hFile, &bytesAvailable, 0, 0))
			{
				const int BUFFLEN = 1024;
				TCHAR buffer[BUFFLEN];
				DWORD dwRead;
	
				while (InternetReadFile(hFile, buffer, BUFFLEN - sizeof(TCHAR), &dwRead))
				{
					if (dwRead == 0)
						break;
	
					buffer[dwRead / sizeof(TCHAR)] = _T('\0');
					retval += buffer;
				}
	
				InternetCloseHandle(hFile);
			}
		}

		InternetCloseHandle(hSession);
	}

	return retval;
}
开发者ID:kragen,项目名称:mod_pubsub,代码行数:41,代码来源:RSS.cpp

示例9: GetHttpString

CString GetHttpString( LPCWSTR pszUrl )
{
	HINTERNET hInternet1 = NULL;
	HINTERNET hInternet2 = NULL;
	CString strPageContent;

	do 
	{
		hInternet1 = InternetOpenW(NULL,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,NULL);
		if (NULL == hInternet1)
		{
			break;
		}
		BOOL bOption = TRUE;
		BOOL bSetRes = InternetSetOption(hInternet1,INTERNET_OPTION_HTTP_DECODING,&bOption,sizeof(BOOL));

		WCHAR szHeaderAdd[] = L"Accept-Encoding: gzip, deflate";
		HINTERNET hInternet2 = InternetOpenUrlW(hInternet1,pszUrl,szHeaderAdd,wcslen(szHeaderAdd),INTERNET_FLAG_NO_CACHE_WRITE,NULL);
		if (NULL == hInternet2)
		{
			break;
		}


		DWORD dwReadDataLength = NULL;
		BOOL bRet = TRUE;
		do 
		{
			CHAR chReadBuffer[4097];
			bRet = InternetReadFile(hInternet2,chReadBuffer,4096,&dwReadDataLength);
			chReadBuffer[dwReadDataLength] = 0;
			strPageContent+=chReadBuffer;
		} while (bRet && NULL != dwReadDataLength);

	} while (FALSE);

	InternetCloseHandle(hInternet2);
	InternetCloseHandle(hInternet1);

	return strPageContent;
}
开发者ID:gaozan198912,项目名称:myproject,代码行数:41,代码来源:GetHttpString.cpp

示例10: ViReadFile

// Read from the file
UINT ViReadFile(VI_FILE *f, void *buf, UINT size)
{
	// Validate arguments
	if (f == NULL || buf == NULL)
	{
		return INFINITE;
	}

	if (f->InternetFile == false)
	{
		UINT readsize = MIN(size, f->FileSize - f->IoReadFileSize);
		bool ret;

		if (readsize == 0)
		{
			return 0;
		}

		ret = FileRead(f->io, buf, readsize);

		if (ret == false)
		{
			return INFINITE;
		}

		f->IoReadFileSize += readsize;

		return readsize;
	}
	else
	{
		UINT readsize = 0;

		if (InternetReadFile(f->hHttpFile, buf, size, &readsize) == false)
		{
			return INFINITE;
		}

		return readsize;
	}
}
开发者ID:alex-docker,项目名称:CE-dockerfiles,代码行数:42,代码来源:vpninstall.c

示例11: while

char* CAmHttpSocket::GetPage(const char *url, bool Post, const char *PostData, int PostDataLength)
{
	//did we get an url?
	if (url == NULL)
	{
		LastError = -1;
		return NULL;
	}
	//get the page and store it in ReceivedData...
	if (Post)
	{
		//use http post...
		if (!PostUrl(url, PostData, PostDataLength)) return NULL;
	}
	else
	{
		//use http get
		if (!OpenUrl(url)) return NULL;
	}
	DWORD rd, dwPos = 0;
	while(InternetReadFile(hIS, ReceivedData + dwPos, SIZE_STEP_DEFAULT, &rd))
	{
		if(rd == 0)break;
		if(rd < SIZE_STEP_DEFAULT)
		{
			m_dwLength = dwPos + rd;
			ReceivedData[m_dwLength] = NULL;
			break;
		}
		else
		{
			dwPos += rd;
			m_dwSize = dwPos + SIZE_STEP_DEFAULT;
			ReceivedData = (char*)realloc(ReceivedData, m_dwSize + 1);
			ReceivedData[m_dwSize + 1] = NULL;
		}
	}

	return ReceivedData;
}
开发者ID:killvxk,项目名称:WebbrowserLock,代码行数:40,代码来源:HttpObj.cpp

示例12: InternetSetOption

CString	ABPLTools::DownloadString(CString url, InternetFeedback* pCIF, bool *pbExit)
{
CString			result;
HINTERNET		hSession, hConnect ;
char			szTemp[512] ;
DWORD			dwBytesRead ;
bool			bExit = false;

	if (pbExit==NULL)
		pbExit = &bExit;

	if (hSession = InternetOpen (TEXT("ABP-Launcher (Win)"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0))
	{
		/*unsigned long to = Timeout;
		InternetSetOption(hSession, INTERNET_OPTION_CONNECT_TIMEOUT, &to, sizeof(unsigned long));*/
		if (hConnect = InternetOpenUrl (hSession, url, NULL, 0, INTERNET_FLAG_RELOAD, 0))
		{
			DWORD dwSize = 512, dwIndex=0;
			HttpQueryInfo(hConnect, HTTP_QUERY_CONTENT_LENGTH, szTemp, &dwSize, &dwIndex);
			DWORD totalSize = atol(szTemp);
			DWORD dwTotal=0;
			do
			{	
				dwBytesRead=0;
				if (InternetReadFile (hConnect, szTemp, sizeof (szTemp)-1, &dwBytesRead))
				{
					szTemp[dwBytesRead]=0;
					result.Append(szTemp);
					dwTotal += dwBytesRead;
					if (pCIF)
						pCIF->DownloadFeedback(totalSize, dwTotal);
				}
			}
			while (dwBytesRead > 0 && *pbExit==false);
			InternetCloseHandle (hConnect) ;
		}
		InternetCloseHandle (hSession) ;
	}
	return result ;
}
开发者ID:LVS,项目名称:AGP-Launcher,代码行数:40,代码来源:ABPLTools.cpp

示例13: InternetDownload

void InternetDownload(const std::wstring strUrl)
{
	char buffer[100000];//下载文件的缓冲区

	DWORD dwBufferRead;//下载的字节数


	//打开一个internet连接

	HINTERNET hInternet=InternetOpen(_T("HTTP Downloader"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL);

	if(NULL == hInternet)
	{
		TSDEBUG4CXX(L"[InternetDownload] InternetOpen error, code = "<<::GetLastError());
		return;
	}
	//打开一个http url地址
	HINTERNET hFile=InternetOpenUrl(hInternet, strUrl.c_str(), NULL, 0, INTERNET_FLAG_RELOAD, 0);

	if(NULL == hFile)
	{
		InternetCloseHandle(hInternet);
		TSDEBUG4CXX(L"[InternetDownload]  InternetOpenUrl error, code = "<<::GetLastError());
		return;
	}

	BOOL bRead = InternetReadFile(hFile, buffer, 100000, &dwBufferRead);
	if(!bRead)
	{
		InternetCloseHandle(hFile);
		InternetCloseHandle(hInternet);
		TSDEBUG4CXX(L"[InternetDownload]  InternetReadFile error, code = "<<::GetLastError());
		return;
	}

	//关闭连接
	InternetCloseHandle(hFile);
	InternetCloseHandle(hInternet);
}
开发者ID:yuanbaoyuele,项目名称:yuanbaoyule,代码行数:39,代码来源:LuaAsynAPIUtil.cpp

示例14: CreateFile

/*Returns full path to file.
TODO: Check if the file is older than 5-10 minutes, if not just return file path
*/
std::string SteamWebAPI::getSteamXML(std::string URL, std::string filename){
	std::string path = std::string("C:\\Windows\\Temp\\").append(filename);

	HANDLE file = CreateFile(s2ws(path).c_str(),(GENERIC_READ | GENERIC_WRITE), 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

	//check to see if the file is still relatively new, new meaning ~10 minutes here
	//this looks sloppy and needs refactored
	if(GetLastError() != 183){
		std::cout << "file had to be created" << std::endl;
	}
	else if(!pastThreshold(file)){
		std::cout << "file is not past time threshhold" << std::endl;
		CloseHandle(file);
		return path;
	}
	else
		std::cout << "Creating new file" << std::endl;


	HINTERNET hOpen = InternetOpen(L"DotaRain", NULL, NULL, NULL, NULL);
	HINTERNET hURL = InternetOpenUrl(hOpen, s2ws(URL).c_str(), NULL, NULL, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, NULL);

	DWORD dwBytesRead =0;
	DWORD dwBytesWritten = 0;
	do {
		char* lpBuffer = new char[2000];
		ZeroMemory(lpBuffer, 2000);
		InternetReadFile(hURL, (LPVOID)lpBuffer, 2000, &dwBytesRead);
		WriteFile(file, (LPVOID)lpBuffer, dwBytesRead, &dwBytesWritten, NULL);
		delete[] lpBuffer;
		lpBuffer = NULL;
	} while (dwBytesRead);

	InternetCloseHandle(hURL);
	InternetCloseHandle(hOpen);
	CloseHandle(file);
	return path;
}
开发者ID:BadStreff,项目名称:DotaRain,代码行数:41,代码来源:SteamWebAPI.cpp

示例15: FtpOpenFileA

bool WebIO::DownloadFileData(std::string file, std::string &data)
{
	data.clear();

	WebIO::m_hFile = FtpOpenFileA(WebIO::m_hConnect, file.c_str(), GENERIC_READ, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0);

	if (WebIO::m_hFile)
	{
		DWORD size = 0;
		char buffer[0x2001] = { 0 };

		while (InternetReadFile(WebIO::m_hFile, buffer, 0x2000, &size))
		{
			data.append(buffer, size);
			if (!size) break;
		}

		InternetCloseHandle(WebIO::m_hFile);
		return true;
	}

	return false;
}
开发者ID:Convery,项目名称:SteamBase,代码行数:23,代码来源:WebIO.cpp


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