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


C++ InternetCloseHandle函数代码示例

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


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


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