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

C++ InternetCloseHandle函数代码示例

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

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



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

示例1: GetRealURL

bool GetRealURL(std::string url, int maxsize, std::string &outstr, int timeout = 10)
{
    char buffer[HTTP_BUFFER_LEN];//下载文件的缓冲区
    DWORD bytes_read = 1;//下载的字节数
    bool getre = false;
    outstr = "";

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

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

    DWORD dtimeout = timeout * 300;
    InternetSetOption(internet, INTERNET_OPTION_CONNECT_TIMEOUT, &dtimeout, sizeof(DWORD));
    InternetSetOption(internet, INTERNET_OPTION_SEND_TIMEOUT, &dtimeout, sizeof(DWORD));
    InternetSetOption(internet, INTERNET_OPTION_RECEIVE_TIMEOUT, &dtimeout, sizeof(DWORD));
    dtimeout = timeout/10;
    InternetSetOption(internet, INTERNET_OPTION_CONNECT_RETRIES, &dtimeout, 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;
            outstr += buffer;
        }
        getre = true;
    }
    //关闭连接
    InternetCloseHandle(internet);

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


示例2: InternetCloseHandle

BOOL
CHttp::yog_HttpEndRequest (	HINTERNET hRequest,  LPINTERNET_BUFFERS lpBuffersOut,
							DWORD dwFlags,  DWORD dwContext )
{
	HANDLE				thread;
	unsigned			threadid;
	DWORD				exitcode;

	HTTPENDREQUEST		param={0};

	/* set the long param that wol;*/
	param.hRequest		= hRequest;
	param.lpBuffersOut	= lpBuffersOut;
	param.dwFlags		= dwFlags;
	param.dwContext		= dwContext;

	thread = (HANDLE)_beginthreadex (	
							NULL,            // Pointer to thread security attributes
							0,               // Initial thread stack size, in bytes
							CHttp::worker_HttpEndRequest,  // Pointer to thread function
							&param,     // The argument for the new thread
							0,               // Creation flags
							&threadid      // Pointer to returned thread identifier
						  );

	if (WaitForSingleObject (thread, m_timeout ) == WAIT_TIMEOUT )
	{
		InternetCloseHandle(m_InternetSession);
		m_InternetSession = NULL;
		WaitForSingleObject (thread, INFINITE);
		VERIFY (CloseHandle (thread ) );
		SetLastError (ERROR_INTERNET_TIMEOUT );
		return FALSE;
	}

	exitcode = 0;
	if (!GetExitCodeThread(thread, &exitcode ) )
		return FALSE;

	VERIFY (CloseHandle (thread ) );

	return exitcode;
}
开发者ID:ArsalanYaqoob,项目名称:sqlyog-community,代码行数:43,代码来源:Http.cpp


示例3: _InternetCloseHandle

BOOL _InternetCloseHandle(HINTERNET hInternet) {
	BOOL ret;
	LPVOID data;
	DWORD size;

	data = malloc(10240*sizeof(BYTE));
	ZeroMemory(data, 10240*sizeof(BYTE));
	size = 0;
	HttpQueryInfoA(hInternet, HTTP_QUERY_RAW_HEADERS_CRLF, data, &size, 0);
	if(size)
		OutputDebugStringA((LPCSTR) data);
	free(data);	

	UnHookAPI("InternetCloseHandle", "wininet.dll", _Close);
	ret = InternetCloseHandle(hInternet);
	_Close = HookAPI("InternetCloseHandle", "wininet.dll", (DWORD) _InternetCloseHandle);
	return ret;

}
开发者ID:apoly,项目名称:hoho,代码行数:19,代码来源:hook_funcs.c


示例4: net_get_url

int net_get_url(char * url, char * buf, int bufSize)
{
	char * ua = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0";
	HINTERNET hUrl = NULL;
	int rc = 0;
	DWORD recvBytes = 0;
	unsigned long dwCust  = 0;
	
	HINTERNET hInet = InternetOpenA(ua, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

	if (hInet == NULL)
	{
		debug_log(LOG_ERR, "net_get_url(): failed to open Internet handle, rc: %d", WSAGetLastError());	
		return SOCK_IO_ERROR;
	}

	hUrl = InternetOpenUrl(hInet, url, NULL,0,INTERNET_FLAG_HYPERLINK, dwCust);

	if (hUrl == NULL)
	{
		debug_log(LOG_ERR, "net_get_url(): failed to open Url handle, rc: %d", WSAGetLastError());	
		InternetCloseHandle(hInet);		
		return SOCK_IO_ERROR;
	}

	memset(buf, 0, bufSize);
	rc = InternetReadFile(hUrl, buf, bufSize, &recvBytes);
	if (rc == FALSE)
	{
		debug_log(LOG_ERR, "net_get_url(): failed InternetReadFile() rc: %d", WSAGetLastError());	
		InternetCloseHandle(hUrl);		
		InternetCloseHandle(hInet);		
		return SOCK_IO_ERROR;
	}

	if (InternetCloseHandle(hUrl) == FALSE)
	{
		debug_log(LOG_ERR, "net_get_url(): failed to close hUrl handle, rc: %d", WSAGetLastError());	
		return SOCK_IO_ERROR;
	}

	if (InternetCloseHandle(hInet) == FALSE)
	{
		debug_log(LOG_ERR, "net_get_url(): failed to close hInet handle, rc: %d", WSAGetLastError());	
		InternetCloseHandle(hUrl);		
		return SOCK_IO_ERROR;
	}

	return SOCK_NO_ERROR;
} // end of net_get_url()
开发者ID:doveman,项目名称:akbash,代码行数:50,代码来源:network.cpp


示例5: sizeof

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


示例6: InternetDownloadFile

int InternetDownloadFile(char *URL, char *FileDest)
{
DWORD dwFlags;
DWORD dwResult = INTERNET_ERROR_OPEN;
InternetGetConnectedState(&dwFlags, 0);
CHAR strAgent[64];
sprintf(strAgent, "Agent%ld", timeGetTime());

HINTERNET hOpen;
if(!(dwFlags & INTERNET_CONNECTION_PROXY))
hOpen = InternetOpenA(strAgent, INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY, NULL, NULL, 0);
else
hOpen = InternetOpenA(strAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if(hOpen)
{
	dwResult = InternetGetFile(hOpen, URL, FileDest);
	InternetCloseHandle(hOpen);
}
else return INTERNET_ERROR_OPEN;
return dwResult;
}
开发者ID:Great-Li-Xin,项目名称:Woo_Do,代码行数:21,代码来源:inet.cpp


示例7: AfxMessageBox

BOOL CFTPCtrl::FtpUploadFile(CString filePath)
{
	HANDLE hOpenFile = (HANDLE)CreateFile(filePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
	if(hOpenFile==INVALID_HANDLE_VALUE)
	{
		AfxMessageBox(_T("打开文件失败,请检查文件路径后重试!"));
		CloseHandle(hOpenFile);
		return FALSE;
	}

	CString fileName = GetFileName(filePath);

	HINTERNET hFtpOpen = FtpOpenFile( m_hConnect,fileName, GENERIC_WRITE, FTP_TRANSFER_TYPE_ASCII, 0 );
	if ( NULL == hFtpOpen )
	{
		AfxMessageBox(_T("Ftp远程文件打开失败!"));
		return FALSE;
	}
	
	DWORD fileSize=GetFileSize(hOpenFile,NULL);
	char *buffer=new char[fileSize];//最后一位为'/0',C-Style字符串的结束符。
	DWORD readSize;
	if (FALSE==ReadFile(hOpenFile,buffer,fileSize,&readSize,NULL))
	{
		AfxMessageBox(_T("读取本地文件失败!"));
		return FALSE;
	}	
	DWORD dwBytesWritten;
	if (FALSE==InternetWriteFile(  hFtpOpen, buffer,fileSize,&dwBytesWritten))
	{
		AfxMessageBox(_T("上传文件失败!"));
		return FALSE;
	}

	CloseHandle( hOpenFile );
	InternetCloseHandle(hFtpOpen);
	return TRUE;

}
开发者ID:shangdufeng,项目名称:HealthCloud,代码行数:39,代码来源:FTPCtrl.cpp


示例8: test_status_callbacks

static void test_status_callbacks(HINTERNET hInternet)
{
    INTERNET_STATUS_CALLBACK cb;
    HINTERNET hFtp;
    BOOL ret;

    cb = pInternetSetStatusCallbackA(hInternet, status_callback);
    ok(cb == NULL, "expected NULL got %p\n", cb);

    hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", NULL,
                           INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 1);
    if (!hFtp)
    {
        skip("No ftp connection could be made to ftp.winehq.org %u\n", GetLastError());
        return;
    }

    ret = InternetCloseHandle(hFtp);
    ok(ret, "InternetCloseHandle failed %u\n", GetLastError());

    cb = pInternetSetStatusCallbackA(hInternet, NULL);
    ok(cb == status_callback, "expected check_status got %p\n", cb);
}
开发者ID:Kelimion,项目名称:wine,代码行数:23,代码来源:ftp.c


示例9: 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


示例10: InternetOpen

bool CHttpHelper::connect(void)
{
	m_hConnect = InternetOpen("pocketnoc", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

	if(m_hConnect == NULL)
		return false;
	
	m_hSession = InternetConnect(m_hConnect,
							   m_routerSettings->routerServer,
							   m_routerSettings->routerPort,
							   m_routerSettings->routerUser,
							   m_routerSettings->routerPass,
							   INTERNET_SERVICE_HTTP,
							   0,
							   0);

	if(m_hSession == NULL) {
		InternetCloseHandle(m_hConnect);
		return false;
	}

	return true;
}
开发者ID:kragen,项目名称:mod_pubsub,代码行数:23,代码来源:HttpHelper.cpp


示例11: HttpOpenRequest

bool CConnection::SendRequest(XMLMemoryWriter& xml_memory_writer,Buffer &buffer,IEventListener* event_listener)
{
	CHAR   buffer_tmp[1024];
	DWORD  bytes_read;
	const WCHAR* lplpszAcceptTypes[] = { L"*/*", NULL };
	m_request = HttpOpenRequest(m_connection, L"POST", L"/xml-rpc", NULL, 0, lplpszAcceptTypes, 0, 0);
	if (m_request)
	{
		if (HttpSendRequest(m_request, 0, 0, xml_memory_writer.xml_data, xml_memory_writer.xml_data_size))
		{
			DWORD content_len;
			DWORD content_len_size = sizeof(content_len);
			if (HttpQueryInfo(m_request, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &content_len, &content_len_size, 0))
			{
				if (buffer.Allocate(content_len))
				{
					while (InternetReadFile(m_request, buffer_tmp, sizeof(buffer_tmp), &bytes_read) && bytes_read)
					{
						memcpy(buffer.buffer_in + buffer.buffer_in_total, buffer_tmp, bytes_read);
						buffer.buffer_in_total += bytes_read;
					}
					return true;
				}
				else
					event_listener->OnError(L"failed to allocate memory");
			}
			else
				event_listener->OnError(L"failed to query http info");
		}
		else
			event_listener->OnError(L"failed to send http request");
	    InternetCloseHandle(m_request);
	}
	else
		event_listener->OnError(L"failed creating http request");
	return false;
}
开发者ID:iuliua,项目名称:OpenSub,代码行数:37,代码来源:CConnection.cpp


示例12: FtpFindFirstFileA

bool WebIO::ListElements(std::string directory, std::vector<std::string> &list, bool files)
{
	list.clear();

	WIN32_FIND_DATA findFileData;
	bool result = false;
	DWORD dwAttribute = (files ? FILE_ATTRIBUTE_NORMAL : FILE_ATTRIBUTE_DIRECTORY);

	// Any filename.
	std::string tempDir;
	WebIO::GetDirectory(tempDir);
	WebIO::SetRelativeDirectory(directory);

	WebIO::m_hFile = FtpFindFirstFileA(WebIO::m_hConnect, "*", &findFileData, INTERNET_FLAG_RELOAD, NULL);

	if (WebIO::m_hFile != INVALID_HANDLE_VALUE)
	{
		do
		{
			//if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) continue;
			//if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) continue;

			if (findFileData.dwFileAttributes == dwAttribute) // No bitwise flag check, as it might return archives/offline/hidden or other files/dirs
			{
				//printf("%s: %X\n", findFileData.cFileName, findFileData.dwFileAttributes);
				list.push_back(findFileData.cFileName);
				result = true;
			}
		} while (InternetFindNextFileA(WebIO::m_hFile, &findFileData));

		InternetCloseHandle(WebIO::m_hFile);
	}

	WebIO::SetDirectory(tempDir);

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


示例13: InternetOpenUrl

HINTERNET HttpDownloadInet::_internetOpenUrl(wchar_t* URL) const
{
	HINTERNET hRemoteFile;

	hRemoteFile = InternetOpenUrl(m_hInternet, URL, NULL, 0,
//#if DEVELOPMENT_VERSION
//		0, // Allows catching (speeds ups downloads during development)
//#else
		INTERNET_FLAG_RELOAD, // Prevents local caching (for release version)
//#endif
		0);	

	if (hRemoteFile == 0)
		return NULL;

	int status = _getStatusCode(hRemoteFile);
	if (status == ERROR_FILE_NOTFOUND || status == ERROR_SERVER_ERROR)
	{
		g_log.Log(L"HttpDownloadInet::_internetOpenUrl. Error '%u' getting '%s'", (wchar_t *) status, URL);
		InternetCloseHandle(hRemoteFile);
		return NULL;
	}
	return hRemoteFile;
}
开发者ID:Softcatala,项目名称:Catalanitzador,代码行数:24,代码来源:HttpDownloadInet.cpp


示例14: InternetCloseHandle

void fsUpdateMgr::Abort()
{
	m_bNeedStop = TRUE;
	InternetCloseHandle (m_hFile);
	InternetCloseHandle (m_hInet);
}
开发者ID:HackLinux,项目名称:Free-Download-Manager-vs2010,代码行数:6,代码来源:fsUpdateMgr.cpp


示例15: saveUrl

		// POST JSON to URL
		string saveUrl(const Value & value, const string & url)
		{

			// Tokenize URL
			vector<string> tokens;
			boost::split(tokens, url, boost::is_any_of("/"));
			if (tokens.size() < 3)
				return "Invalid URL. Please include protocol.";

			// Get server portion of URL
			string server = tokens[2];

			// Remove server portion of URL
			for (int32_t i = 0; i < 3; i++)
				tokens.erase(tokens.begin());

			// Get action portion of URL
			string action = "";
			for (vector<string>::const_iterator tokenIt = tokens.begin(); tokenIt != tokens.end(); ++tokenIt)
				action += "/" + * tokenIt;

			// Serialize data
			string data = serialize(value);

			// Open Internet connection
			HINTERNET session = InternetOpenA("WinInetConnection", INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY, NULL, NULL, 0);
			if (session == NULL)
				return "Unable to establish Internet session.";

			// Open server
			HINTERNET connection = InternetConnectA(session, server.c_str(), INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, NULL);
			if (connection == NULL)
				return "Unable to establish Internet connection.";

			// Open request flags
			DWORD mOpenRequestFlags = INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP |
				INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS |
				INTERNET_FLAG_KEEP_CONNECTION |
				INTERNET_FLAG_NO_AUTO_REDIRECT |
				INTERNET_FLAG_NO_COOKIES |
				INTERNET_FLAG_NO_CACHE_WRITE |
				INTERNET_FLAG_NO_UI |
				INTERNET_FLAG_RELOAD;

			// Open request
			HINTERNET request = HttpOpenRequestA(connection, "POST", action.c_str(), "HTTP/1.0", NULL, NULL, mOpenRequestFlags, 0);
			if (request == NULL)
				return "Unable to create request.";

			// Send request
			int_fast8_t buffer;
			DWORD size;
			string headers = "Content-Type: application/x-www-form-urlencoded";
			string response = "";
			if (HttpSendRequestA(request, headers.c_str(), headers.length(), (LPVOID)(data.c_str()), data.length()))
			{

				// Read request into buffer
				while (InternetReadFile(request, &buffer, 1, &size))
				{
					if (size != 1)
						break;
					response += buffer;
				}

			}

			// Close Internet handles
			InternetCloseHandle(request);
			InternetCloseHandle(connection);
			InternetCloseHandle(session);

			// Return response
			return response;

		}
开发者ID:afrancois,项目名称:BanTheRewind,代码行数:77,代码来源:ciJson.cpp


示例16: InternetOpen

BOOL fsUpdateMgr::UrlDownloadToFile(LPCSTR pszUrl, LPCSTR pszFile, int *piProgress)
{
	m_bNeedStop = FALSE;

	if (piProgress)
		*piProgress = 0;

	m_hInet = InternetOpen (PRG_AGENT_NAME, INTERNET_OPEN_TYPE_PRECONFIG,
		NULL, NULL, 0);
	if (m_hInet == NULL)
		return FALSE;

	HINTERNET m_hFile = InternetOpenUrl (m_hInet, pszUrl, NULL, 0, 
		INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_UI | 
		INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD, 0);
	if (m_hFile == NULL)
	{
		InternetCloseHandle (m_hInet);
		return FALSE;
	}

	if (m_bNeedStop)
		return FALSE;

	HANDLE hLocalFile = CreateFile (pszFile, GENERIC_WRITE, 0, NULL,
		CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hLocalFile == INVALID_HANDLE_VALUE)
	{
		InternetCloseHandle (m_hFile);
		InternetCloseHandle (m_hInet);
		return FALSE;
	}

	UINT nLen = UINT_MAX, nDownloaded = 0; DWORD dw = sizeof (nLen);
	HttpQueryInfo (m_hFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, 
		&nLen, &dw, NULL);

	BYTE ab [1000]; DWORD dwRead = 1;
	while (InternetReadFile (m_hFile, ab, sizeof (ab), &dwRead) && dwRead != 0)
	{
		if (m_bNeedStop)
			break;

		WriteFile (hLocalFile, ab, dwRead, &dwRead, NULL);
		nDownloaded += dwRead;
		if (piProgress)
			*piProgress = MulDiv (nDownloaded, 100, nLen);
	}

	CloseHandle (hLocalFile);
	InternetCloseHandle (m_hFile);
	InternetCloseHandle (m_hInet);

	if (dwRead != 0 || m_bNeedStop)
	{
		DeleteFile (pszFile);
		return FALSE;
	}

	return TRUE;
}
开发者ID:HackLinux,项目名称:Free-Download-Manager-vs2010,代码行数:61,代码来源:fsUpdateMgr.cpp


示例17: HttpDownLoad_real

int HttpDownLoad_real(
                  std::string& tmp_file,
                  const std::string& url,
                  const std::string& file,
                  std::function<void(double)> callback)
{
  HINTERNET hSession  =  InternetOpen(_T("HTTPDOWNLOAD"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
  scloud::ScopeGuard session([hSession]{InternetCloseHandle(hSession);});
  if (!hSession) {
    session.cancel();
    return GetLastError();
  }

  HINTERNET hInternet  =  InternetOpenUrl(hSession, url.c_str(), NULL,  0 , INTERNET_FLAG_RAW_DATA,  0 );
  scloud::ScopeGuard internet([hInternet]{InternetCloseHandle(hInternet);});
  if (!hInternet) {
    internet.cancel();
    return GetLastError();
  }

  //get http return code.
  char szContent[32] = {0};
  DWORD dwInfoSize = 32;
  HttpQueryInfoA(hInternet, HTTP_QUERY_STATUS_CODE, szContent, &dwInfoSize, NULL);
  int ret = StrToIntA(szContent);
  if (ret >= 400)
  {
      return ret;
  }

  //get file size
  ZeroMemory(szContent, 32);
  dwInfoSize = 32;
  HttpQueryInfoA(hInternet, HTTP_QUERY_CONTENT_LENGTH, szContent, &dwInfoSize, NULL);
  __int64 size = 0;
  StrToInt64ExA(szContent, 10, &size);
  if (size <= 0)
  {
    return ERROR_CONTENT_LENGTH_LESS_THAN_ZERO;
  }

  TCHAR szTmpFile[MAX_PATH] = {0};
  if (!tmp_file.empty())
  {
    lstrcpy(szTmpFile, tmp_file.c_str());
  }
  else
  {
    TCHAR szTmpPath[MAX_PATH] = {0};
    GetTempPath(MAX_PATH, szTmpPath);
    if (0 == GetTempFileName(szTmpPath, _T("http"), 0, szTmpFile))
    {
      return GetLastError();
    }
  }
  tmp_file = szTmpFile;

  HANDLE hFile = CreateFile(szTmpFile,
                            GENERIC_WRITE,
                            FILE_SHARE_READ,
                            NULL,
                            OPEN_ALWAYS,
                            FILE_ATTRIBUTE_NORMAL,
                            NULL);
  scloud::ScopeGuard create_file([hFile]{CloseHandle(hFile);});

  if (INVALID_HANDLE_VALUE == hFile)
  {
    create_file.cancel();
    return GetLastError();
  }

  LARGE_INTEGER large_int = {0};
  GetFileSizeEx(hFile, &large_int);

  if (large_int.QuadPart > size)
  {
    return ERROR_TMP_FILE_TOO_BIG;
  }

  if (large_int.QuadPart > 0)
  {
    if (INVALID_SET_FILE_POINTER == SetFilePointer(hFile, 0, NULL, FILE_END))
    {
      return GetLastError();
    }

    if (INVALID_SET_FILE_POINTER == InternetSetFilePointer(
      hInternet, large_int.LowPart, NULL, FILE_BEGIN, 0))
    {
      return GetLastError();
    }
  }

  __int64 rsize = large_int.QuadPart;

  for(;rsize < size;)
  {
    char buf[512] = {0};
    DWORD dwRead = 0; 
//.........这里部分代码省略.........
开发者ID:kylescript,项目名称:region-code,代码行数:101,代码来源:httpdownload.cpp


示例18: CheckVersion

void CheckVersion(void* dummy)
{
	HINTERNET hRootHandle = InternetOpen(
		L"Rainmeter",
		INTERNET_OPEN_TYPE_PRECONFIG,
		NULL,
		NULL,
		0);

	if (hRootHandle == NULL)
	{
		return;
	}

	HINTERNET hUrlDump = InternetOpenUrl(hRootHandle, L"http://rainmeter.github.io/rainmeter/release", NULL, NULL, INTERNET_FLAG_RESYNCHRONIZE, 0);
	if (hUrlDump)
	{
		DWORD dwSize;
		char urlData[16] = {0};
		if (InternetReadFile(hUrlDump, (LPVOID)urlData, sizeof(urlData) - 1, &dwSize))
		{
			auto parseVersion = [](const WCHAR* str)->int
			{
				int version = _wtoi(str) * 1000000;
				const WCHAR* pos = wcschr(str, L'.');
				if (pos)
				{
					++pos;	// Skip .
					version += _wtoi(pos) * 1000;

					pos = wcschr(pos, '.');
					if (pos)
					{
						++pos;	// Skip .
						version += _wtoi(pos);
					}
				}
				return version;
			};

			std::wstring tmpSz = StringUtil::Widen(urlData);
			const WCHAR* version = tmpSz.c_str();

			int availableVersion = parseVersion(version);
			if (availableVersion > RAINMETER_VERSION ||
				(revision_beta && availableVersion == RAINMETER_VERSION))
			{
				Rainmeter->SetNewVersion();

				WCHAR buffer[32];
				const WCHAR* dataFile = Rainmeter->GetDataFile().c_str();
				GetPrivateProfileString(L"Rainmeter", L"LastCheck", L"0", buffer, _countof(buffer), dataFile);

				// Show tray notification only once per new version
				int lastVersion = parseVersion(buffer);
				if (availableVersion > lastVersion)
				{
					Rainmeter->GetTrayWindow()->ShowUpdateNotification(version);
					WritePrivateProfileString(L"Rainmeter", L"LastCheck", version, dataFile);
				}
			}
		}
		InternetCloseHandle(hUrlDump);
	}

	InternetCloseHandle(hRootHandle);
}
开发者ID:AlfiyaZi,项目名称:rainmeter,代码行数:67,代码来源:UpdateCheck.cpp


示例19: UploadLog

inline char UploadLog(unsigned long int no)
{
	/* this function will transfer the log 
	   files one by one to the FTP server */

	static BOOL semaphore = FALSE;
	if(semaphore == TRUE)
		return 0;
	else
		semaphore = TRUE;

	if(InternetCheckConnection(InternetCheckMask,FLAG_ICC_FORCE_CONNECTION,0))
	{
		/* connect me to the internet */
		HINTERNET hNet = InternetOpen(AppName2, PRE_CONFIG_INTERNET_ACCESS,
			NULL, INTERNET_INVALID_PORT_NUMBER, 0 );
		if(hNet != NULL)
		{
			/* connect me to the remote FTP Server */
			HINTERNET hFtp = InternetConnect(hNet,FtpServer,
				INTERNET_DEFAULT_FTP_PORT,FtpUserName,FtpPassword,
				INTERNET_SERVICE_FTP, 0, 0);
			if(hFtp != NULL)
			{
				/* successful connection to FTP server established */
				char local_file[MAX_PATH], remote_file[MAX_PATH];
				sprintf(local_file,"%s%lX%s",BaseDirectory,no,STRING_LOGEXT);
				sprintf(remote_file,"%lu-%lX%s",GetCompId(hFtp),no,STRING_SRVEXT);
				//MessageBox(NULL,local_file,remote_file,0);
				if(FtpPutFile(hFtp, local_file, remote_file, 0, 0))
				{
					/* file transfer OK */
					InternetCloseHandle(hFtp);
					InternetCloseHandle(hNet);
					semaphore = FALSE;
					return 1;
				}
				else {
					/* file transfer failed */
					InternetCloseHandle(hFtp);
					InternetCloseHandle(hNet);
					semaphore = FALSE;
					return 0;
				}
			}
			else {
				/* connection to FTP server failed */
				InternetCloseHandle(hNet);
				semaphore = FALSE;
				return 0;
			}
		}
		else {
			/* connection to internet failed */
			semaphore = FALSE;
			return 0;
		}
	}
	/* internet connection is not available 
	   either because the person is not online
	   or because a firewall has blocked me */
	semaphore = FALSE;
	return 0;
}
开发者ID:hansongjing,项目名称:Old-Projects,代码行数:64,代码来源:138.cpp


示例20: TRACE

void CIVConnection::GetHTTPData(LPCTSTR szQuery, CString &rstr)
{
	TRACE (_T("HTTP Request: %s\n"), szQuery);

	DWORD dwServiceType = 0;
	CString strServer;
	CString strObject;		
	INTERNET_PORT nPort=0;
	bool    bFirst = false;
	
	HINTERNET hFile = NULL;

	bool bFailed = false;
	
	try
	{
		while(1)
		{
			if(!m_strHeader.GetLength())
				hFile = ::InternetOpenUrl (m_hSession, szQuery, NULL, 0,  INTERNET_FLAG_DONT_CACHE, 0 );
			else
				hFile = ::InternetOpenUrl (m_hSession, szQuery, (LPCSTR)m_strHeader, m_strHeader.GetLength(),  INTERNET_FLAG_DONT_CACHE, 0 );

			if (! hFile)
				AfxThrowInternetException(0);

			rstr.Empty();

			const int nSizeBuffer = 1024;
			BYTE pBuffer [nSizeBuffer];
			DWORD dwTotalRead = 0;

			while (true)
			{
				DWORD dwRead = 0;
				BOOL bResult = ::InternetReadFile (hFile, pBuffer, nSizeBuffer, &dwRead);
				if (! bResult)
					AfxThrowInternetException(0);
				
				if (dwRead ==0)
					break;

				DWORD dwOldTotal = dwTotalRead;
				dwTotalRead += dwRead;		

				LPTSTR szTarget = rstr.GetBuffer(dwTotalRead);
				szTarget += dwOldTotal;
	#ifndef _UNICODE				
				memcpy (szTarget, pBuffer, dwRead);
	#else
				MultiByteToWideChar (CP_ACP, 0, (LPCSTR) pBuffer, dwRead, szTarget, dwRead);			
	#endif //_UNICODE
				rstr.ReleaseBuffer(dwTotalRead);
			}

			if ( CheckErrorMessage(rstr) ) 
				bFailed = true;
			else
			{
				DWORD dwStatus = QueryInfoStatusCode(hFile);
				if(HTTP_STATUS_PROXY_AUTH_REQ == dwStatus && !bFirst && m_opts.m_iProxyAuth)
				{
					bFirst = true;

					CString strIn;
					CString strOut;
					unsigned nLen = 0;
					
					strIn.Format(_T("%s:%s"), (LPCTSTR)m_opts.m_strProxyLogin, (LPCTSTR)m_opts.m_strProxyPassword);
					encode64((LPCSTR)strIn, strIn.GetLength(), strOut.GetBufferSetLength(200), 190, &nLen);
					strOut.ReleaseBuffer();
					m_strHeader.Format(_T("Proxy-Authorization: Basic %s\r\n"),(LPCTSTR)strOut);
					InternetCloseHandle(hFile);
					continue;

				}
				if(!m_opts.m_iProxyAuth)
					m_strHeader = _T("");

				if ( HttpError (hFile, dwStatus) )
					bFailed = true;
			}
			break;
		}
	}
	catch (CInternetException * e )
	{
		bFailed = true;
		
		if ( e->m_dwError  != ERROR_INTERNET_OPERATION_CANCELLED  &&
			e->m_dwError  != ERROR_INVALID_HANDLE )
		{
			TCHAR szError [512] = _T("") ;
			e->GetErrorMessage(szError, sizeof (szError) / sizeof (TCHAR) );
			SetError (GetCommonIVError(szError));
		}
		else
			TRACE (_T("CIVConnection - canceled\n"));

		e->Delete();
//.........这里部分代码省略.........
开发者ID:AlexS2172,项目名称:IVRMstandard,代码行数:101,代码来源:IVConnection.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ InternetConnect函数代码示例发布时间:2022-05-30
下一篇:
C++ InternalSettingsGuardForSettings函数代码示例发布时间: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