亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? crobotinternet.cpp

?? Visual C++自動查詢和智能代理程序設計書籍源碼-AnyQuote
?? CPP
?? 第 1 頁 / 共 4 頁
字號:
////////////////////////////////////////////////////////////////////
//
//  CRobotInternet.cpp - CRobotInternet class implementation
//
//  Source: "Programming Robots, Spiders and Intelligent Agents
//           using Visual C++"
//
//	Copyright (C) 1999 David Pallmann. All Rights Reserved.


#include <stdafx.h>
#include <afxinet.h>
#include "CRobot.h"
#include "CRobotInternet.h"


// Constructor

CRobotInternet::CRobotInternet()
{
	m_bReadFromCache = false;
	m_bWriteToCache = false;
	m_nContext = 0;
	m_sLogonUsername = "";
	m_sLogonPassword = "";
	m_sProxyLogonMethod = "";
	m_sProxyLogonUsername = "";
	m_sProxyLogonPassword = "";
	m_sUserAgent = "Mozilla";
}


// Destructor

CRobotInternet::~CRobotInternet()
{
	m_sProxyLogonMethod.Empty();
	m_sProxyLogonUsername.Empty();
	m_sProxyLogonPassword.Empty();
}


////////////////////////////////////////////////////////////////////
//
// Support functions


// ********************** private
// *                    *
// *  EncodeTextBase64  *
// *                    *
// **********************
// Function: Returns the Base64-encoded version of a text string.

CString CRobotInternet::EncodeTextBase64(const CString& sText)
{
	unsigned char cChar[255];
	int nIndex1, nIndex2, nIndex3, nIndex4;
	int nChars;
	CString sBase64 = "";
	char cTable[64 + 1];
	CString sTemp;

	cTable[0] = 'A';
	cTable[1] = 'B';
	cTable[2] = 'C';
	cTable[3] = 'D';
	cTable[4] = 'E';
	cTable[5] = 'F';
	cTable[6] = 'G';
	cTable[7] = 'H';
	cTable[8] = 'I';
	cTable[9] = 'J';
	cTable[10] = 'K';
	cTable[11] = 'L';
	cTable[12] = 'M';
	cTable[13] = 'N';
	cTable[14] = 'O';
	cTable[15] = 'P';

	cTable[16] = 'Q';
	cTable[17] = 'R';
	cTable[18] = 'S';
	cTable[19] = 'T';
	cTable[20] = 'U';
	cTable[21] = 'V';
	cTable[22] = 'W';
	cTable[23] = 'X';
	cTable[24] = 'Y';
	cTable[25] = 'Z';
	cTable[26] = 'a';
	cTable[27] = 'b';
	cTable[28] = 'c';
	cTable[29] = 'd';
	cTable[30] = 'e';
	cTable[31] = 'f';

	cTable[32] = 'g';
	cTable[33] = 'h';
	cTable[34] = 'i';
	cTable[35] = 'j';
	cTable[36] = 'k';
	cTable[37] = 'l';
	cTable[38] = 'm';
	cTable[39] = 'n';
	cTable[40] = 'o';
	cTable[41] = 'p';
	cTable[42] = 'q';
	cTable[43] = 'r';
	cTable[44] = 's';
	cTable[45] = 't';
	cTable[46] = 'u';
	cTable[47] = 'v';

	cTable[48] = 'w';
	cTable[49] = 'x';
	cTable[50] = 'y';
	cTable[51] = 'z';
	cTable[52] = '0';
	cTable[53] = '1';
	cTable[54] = '2';
	cTable[55] = '3';
	cTable[56] = '4';
	cTable[57] = '5';
	cTable[58] = '6';
	cTable[59] = '7';
	cTable[60] = '8';
	cTable[61] = '9';
	cTable[62] = '+';
	cTable[63] = '/';

	cTable[64] = '=';

	nChars = sText.GetLength();
	for (int nPos = 0; nPos < nChars; nPos++) 
	{
		cChar[nPos] = sText.GetAt(nPos);
	} // End for

	//   cChar[nPos]    cChar[nPos+1]   cChar[nPos+2]
	//        |               |               |
	// -------+------- -------+------- -------+-------
	// 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
	// | | | | | | | | | | | | | | | | | | | | | | | |
	// x x x x x x x x x x x x x x x x x x x x x x x x
	// | | | | | | | | | | | | | | | | | | | | | | | |
	// 5 4 3 2 1 0 5 4 3 2 1 0 5 4 3 2 1 0 5 4 3 2 1 0
	// -----+----- -----+----- -----+----- -----+-----
	//      |           |           |           |
	//   nIndex1     nIndex2     nIndex3     nIndex4
	//

	for (nPos = 0; nPos < nChars; nPos += 3)
	{
		if (nPos + 1 >= nChars) cChar[nPos + 1] = '0';
		if (nPos + 2 >= nChars) cChar[nPos + 2] = '0';
		nIndex4 = ( cChar[nPos + 2] & 0x3F ) & 0x3F;
		nIndex3 = ( ((cChar[nPos + 1] & 0x0F) << 2) 
					| ((cChar[nPos + 2] & 0xC0) >> 6) ) & 0x3F;
		nIndex2 = ( ((cChar[nPos] & 3) << 4) 
					| ((cChar[nPos + 1] & 0xF0) >> 4) ) & 0x3F;
		nIndex1 = ( (cChar[nPos] & 0xFC) >> 2 ) & 0x3F;
		if (nPos + 1 >= nChars)
		{
			nIndex3 = 64;
			nIndex4 = 64;
		} // end if
		if (nPos + 2 >= nChars)
		{
			nIndex4 = 64;
		} // end if
		sTemp.Format("%c%c%c%c",
					 cTable[nIndex1],
					 cTable[nIndex2],
					 cTable[nIndex3],
					 cTable[nIndex4]);
		sBase64 += sTemp;
	} // End for

	return sBase64;
}


// ********************* private
// *                   *
// *  ResponseMessage  *
// *                   *
// *********************
// Function: Returns a textual message describing 
//           a TCP/IP response code.

CString CRobotInternet::ResponseMessage(const int nCode)
{
	CString sErrMsg = "";

	switch (nCode)
	{
	//---- 200 series (success) ----
	case 200:
		sErrMsg = "OK, request succeeded";
		break;
	case 201:
		sErrMsg = "OK, new resource created.";
		break;
	case 202:
		sErrMsg = "Request accepted but processing not completed.";
		break;
	case 204:
		sErrMsg = "OK, but no content to return.";
		break;
	//---- 300 series (redirection) ----
	case 301:
		sErrMsg = "Requested resource has been assigned a "
				  "new permanent URL.";
		break;
	case 302:
		sErrMsg = "Requested resource resides temporarily "
				  "under a different URL.";
		break;
	case 304:
		sErrMsg = "Document has not been modified.";
		break;
	//---- 400 series (client error) ----
	case 400:
		sErrMsg = "Bad request.";
		break;
	case 401:
		sErrMsg = "Unauthorized; request requires "
				  "user authentication.";
		break;
	case 403:
		sErrMsg = "Forbidden for unspecified reason.";
		break;
	case 404:
		sErrMsg = "Not Found.";
		break;
	case 407:
		sErrMsg = "Unauthorized; reject by proxy server.";
		break;
	//---- 500 series (server error) ----
	case 500:
		sErrMsg = "Internal server error.";
		break;
	case 501:
		sErrMsg = "Not implemented.";
		break;
	case 502:
		sErrMsg = "Bad gateway; invalid response from "
				  "gateway or upstream server.";
		break;
	case 503:
		sErrMsg = "Service temporarily unavailable.";
		break;
	default:
		sErrMsg.Format("Error %d", nCode);
		break;
	} // End switch
	return sErrMsg;
}


// ****************** private
// *                *
// *  ErrorMessage  *
// *                *
// ******************
// Function: Returns a textual message describing a CRobot
//           error code.

CString CRobotInternet::ErrorMessage(const int nError)
{
	CString sErrMsg = "";

	switch (nError) 
	{
	case CROBOT_ERR_SUCCESS:
		sErrMsg = "Successful";
		break;
	case CROBOT_ERR_INVALID_URL:
		sErrMsg = "Invalid URL";
		break;
	case CROBOT_ERR_INVALID_PARAMETER:
		sErrMsg = "Invalid parameter";
		break;
	case CROBOT_ERR_CONNECTION_FAILED:
		sErrMsg = "Connection failed";
		break;
	case CROBOT_ERR_TIMED_OUT:
		sErrMsg = "Timed out";
		break;
	case CROBOT_ERR_NOT_FOUND:
		sErrMsg = "Not found";
		break;
	case CROBOT_ERR_NOT_AUTHORIZED:
		sErrMsg = "Not authorized";
		break;
	case CROBOT_ERR_DISK_FILE_ERROR:
		sErrMsg = "Disk/file error";
		break;
	default:
		sErrMsg.Format("CRobotInternet error %d", nError);
		break;
	} // End switch
	return sErrMsg;
}


// **************************************************************
// *															*
// *															*
// *				 H T T P  F u n c t i o n s					*
// *															*
// *															*
// **************************************************************


// ---------------------------------------------------------------
// ************************** private
// *                        *
// *  CreateStandardHeader  *
// *                        *
// **************************
// Function: Return a standard header to use with OpenURL calls.
//           If a call has been made to set proxy logon information,
//           the authentication string is included in the header
//			 that is returned.
//
// This is a private function called by various public functions.

CString CRobotInternet::CreateStandardHeader()
{
	CString sHeader;

	sHeader = "Accept: */*\r\n";

	if (m_sProxyLogonMethod=="basic" && m_sProxyLogonUsername!="")
	{
		sHeader += "Proxy-authorization: Basic "
				   + EncodeTextBase64(m_sProxyLogonUsername 
									  + ":"
									  + m_sProxyLogonPassword)
				   + "\r\n";
	} // End if

	if (m_sLogonUsername != "") 
	{
/*		sHeader += "Authorization: "
				   + m_sLogonUsername
				   + ":"
				   + m_sLogonPassword
				   + "\r\n";
*/
		sHeader += "Authorization: Basic "
				   + EncodeTextBase64(m_sLogonUsername
				                      + ":"
									  + m_sLogonPassword)
				   + "\r\n";
	} // End if

	sHeader += "\r\n";
	return sHeader;
}


// --------------------------------------------------------------
// ************* public
// *           *
// *  httpGet  *
// *           *
// *************
// Function: Retrieves a URL and returns it in CString form.
//
// Inputs:	sURL              - The URL to access
//								 (example: "www.mysite.com")
//
// Outputs:	<function_result> - True if data was successfully
//								 retrieved, false otherwise
//			sResponse         - The HTML retrieved.
//			nResult           - Completion code. 0 = success,
//								 n = error (defined in CRobot.h)
//			sErrMsg           - The error message, if nResult != 0

BOOL CRobotInternet::httpGet(const CString& sURL,
							 CString& sResponse,
							 int& nResult,
							 CString& sErrMsg)
{
	// Variable declarations
	CInternetSession* pSession;
	CHttpFile* pHttpFile;
	CString sHeader;

	int nRead;
	LPSTR pBuffer = NULL;
	CString sResult;
	CString sWorkingUrl;
	CString sMsg;
	sErrMsg = "";
	nResult = CROBOT_ERR_SUCCESS;
	DWORD dwHttpStatus;

	try 
	{
		// Initialize variables
		pSession = NULL;
		pHttpFile = NULL;
		sHeader = CreateStandardHeader();
		nRead = 0;
		pBuffer = new char[1024];
		sResult = "";
		sWorkingUrl = sURL;
		
		/* Trim URL and add http:// if it contains no 
		   protocol identifier */

		sWorkingUrl.TrimLeft();
		sWorkingUrl.TrimRight();
		if (sWorkingUrl.Find(":") == -1) 
		{
			if (sWorkingUrl.Left(1) == "/")
				sWorkingUrl = "http:" + sWorkingUrl;
			else
				sWorkingUrl = "http://" + sWorkingUrl;
		} // End if

		DWORD dwFlags;

		// Check for invalid parameters
		if (!sURL.IsEmpty()) 
		{
			// URL is not empty
			/* Check the URL - must be valid and of the 'http:'
			   service type */
			DWORD dwServiceType;
			CString sServer, sObject;
			unsigned short nPort;
			if (AfxParseURL(sWorkingUrl,
							dwServiceType,
							sServer,
							sObject,
							nPort))
			{
				// URL is valid
				if (dwServiceType == AFX_INET_SERVICE_HTTP)
				{
					//URL is the correct service type (HTTP).
					pSession = new CInternetSession(
									m_sUserAgent,
									++m_nContext,
									INTERNET_OPEN_TYPE_PRECONFIG);

					dwFlags = INTERNET_FLAG_TRANSFER_BINARY 
							  | INTERNET_FLAG_EXISTING_CONNECT;
					if (!m_bReadFromCache) 
						dwFlags = dwFlags | INTERNET_FLAG_RELOAD;
					if (!m_bWriteToCache)
						dwFlags = dwFlags | INTERNET_FLAG_DONT_CACHE;

					pHttpFile = (CHttpFile*) 
									pSession->OpenURL(sWorkingUrl,
													  1,
													  dwFlags,
													  sHeader,
													  -1L);
					if (pHttpFile) /* OpenURL worked */
					{
						// Check the HTTP return code
						if (!pHttpFile->QueryInfoStatusCode(dwHttpStatus))
							dwHttpStatus = 200;

						if (dwHttpStatus >= 400)
						{
							switch(dwHttpStatus)
							{
							case 404:
								nResult = CROBOT_ERR_NOT_FOUND;
								break;
							case 403:
							case 407:
								nResult = CROBOT_ERR_NOT_AUTHORIZED;
								break;
							default:
								nResult = CROBOT_ERR_CONNECTION_FAILED;
								break;
							} // End switch
						} // End if dwHttpStatus
						else /* No error - read response data */
						{
							nResult = CROBOT_ERR_SUCCESS;
							// Read the data
							do 
							{
								nRead = pHttpFile->Read(pBuffer, 1023);
								if (nRead != 0) 
								{
									pBuffer[nRead] = 0;
									sResult += pBuffer;
								} // End if
							} while (nRead != 0);
							sResponse = sResult;
						} // End else
					} // End if pHttpFile
					else /* OpenURL failed */
						nResult = CROBOT_ERR_CONNECTION_FAILED;

				} // End if
				else
					// Wrong service type
					nResult = CROBOT_ERR_INVALID_URL;
			}
			else
				// Invalid URL
				nResult = CROBOT_ERR_INVALID_URL;
		} // End if
		else
			// Empty URL
			nResult = CROBOT_ERR_INVALID_PARAMETER;
	} // End try

	catch (CInternetException* e) 
	{
		e->Delete();
		sResponse = sResult;
		
		// Internet exception occurred
		nResult = CROBOT_ERR_CONNECTION_FAILED;
	} // End catch
	catch (...) 
	{
		sResponse = sResult;
		
		// Exception occurred
		nResult = CROBOT_ERR_CONNECTION_FAILED;
	} // End catch

// Clean up and exit function

	if (pBuffer != NULL) 
	{
		delete pBuffer;
		pBuffer = NULL;
	} // End if

	if (pHttpFile != NULL) 
	{
		pHttpFile->Close();
		delete pHttpFile;
	} // End if

	if (pSession != NULL) 
	{
		pSession->Close();
		delete pSession;
	} // End if

	sErrMsg = ErrorMessage(nResult);
	if (nResult == CROBOT_ERR_SUCCESS)
		return true;
	else
		return false;
}


// --------------------------------------------------------------
// ***************** public
// *               *
// *  httpGetFile  *
// *               *
// *****************
// Function: Retrieves a URL and outputs it to a local file
//
// Inputs:	sURL              - The URL to access
//                               (example: "www.mysite.com")
//			sFile             - File to output to
//                               (example: "c:\temp\file1.gif")
//
// Outputs:	<function_result> - True if data was successfully
//                               retrieved, false otherwise
//			nResult           - Completion code. 0 = success,
//                               n = error (defined in CRobot.h)
//			sErrMsg           - The error message, if nResult != 0

BOOL CRobotInternet::httpGetFile(const CString& sURL,
								 const CString& sOutputFilespec,
								 int& nResult,
								 CString& sErrMsg)
{
	CInternetSession* pSession;
	CHttpFile* pHttpFile;
	CFile* pLocalFile;
	CFileException exFile;
	CString sHeader;
	int nRead;
	LPSTR pBuffer = NULL;
	CString sResult;
	CString sWorkingUrl;
	CString sTemp;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99视频在线精品| 精品成人一区二区| 日韩一区二区三区观看| 国产欧美一区二区三区沐欲| 亚洲国产视频网站| 不卡影院免费观看| 精品99一区二区| 午夜精品久久久| 日本电影亚洲天堂一区| 久久久精品国产免费观看同学| 亚洲成人7777| 色吊一区二区三区| 国产精品欧美综合在线| 狠狠色狠狠色综合系列| 欧美浪妇xxxx高跟鞋交| 伊人色综合久久天天人手人婷| 国产精品一级片| 久久伊99综合婷婷久久伊| 爽好久久久欧美精品| 欧美主播一区二区三区| 久久一区二区视频| 蜜乳av一区二区三区| 欧美日韩精品高清| 亚洲国产综合视频在线观看| 成人av免费在线观看| 欧美国产综合色视频| 国产精品888| 国产人妖乱国产精品人妖| 美女诱惑一区二区| 91精品国产综合久久久久久| 亚洲一区视频在线| 欧洲亚洲精品在线| 亚洲资源在线观看| 欧美日韩免费不卡视频一区二区三区 | 亚洲国产精品一区二区www| 成人av小说网| 中文字幕亚洲视频| 风间由美中文字幕在线看视频国产欧美| 欧美刺激午夜性久久久久久久| 婷婷中文字幕一区三区| 欧美日韩1234| 天天免费综合色| 日韩欧美中文一区| 国产在线精品一区二区夜色 | 欧美人伦禁忌dvd放荡欲情| 艳妇臀荡乳欲伦亚洲一区| 91激情在线视频| 午夜视频在线观看一区| 91精品国产免费| 久久精品国产亚洲a| 欧美一级淫片007| 国产一区二区三区免费观看| 国产日韩欧美精品一区| 成人性生交大片免费看视频在线 | 91国在线观看| 天天综合色天天综合| 日韩视频123| 国产suv精品一区二区6| 亚洲视频一区二区在线观看| 欧洲精品在线观看| 日本少妇一区二区| 国产精品色眯眯| 欧美性猛交xxxx黑人交| 捆绑变态av一区二区三区| 日本一区二区免费在线| 色婷婷久久99综合精品jk白丝| 首页欧美精品中文字幕| 国产日韩av一区二区| 欧美无砖专区一中文字| 精品一区二区成人精品| 亚洲丝袜精品丝袜在线| 91.麻豆视频| 99精品视频在线播放观看| 日韩综合一区二区| 欧美激情自拍偷拍| 51午夜精品国产| 不卡的电影网站| 六月丁香婷婷久久| 亚洲欧洲中文日韩久久av乱码| 日韩欧美aaaaaa| 在线观看一区日韩| 国产成人免费视频网站| 日韩avvvv在线播放| 日韩美女视频一区| 久久久五月婷婷| 欧美另类久久久品| 91亚洲精品久久久蜜桃| 国产资源精品在线观看| 亚洲国产日韩一级| 亚洲色图在线视频| 欧美国产精品一区二区三区| 日韩女优制服丝袜电影| 欧美日韩免费观看一区二区三区| 丁香激情综合五月| 激情五月婷婷综合网| 蜜桃久久精品一区二区| 艳妇臀荡乳欲伦亚洲一区| 国产精品电影一区二区| 日韩精品中午字幕| 欧美久久久久久久久中文字幕| 色综合久久久久久久久| 国产91精品一区二区麻豆亚洲| 蜜臀久久久99精品久久久久久| 亚洲成人动漫av| 夜夜嗨av一区二区三区| 亚洲色图.com| 亚洲美女精品一区| 亚洲理论在线观看| 亚洲人成人一区二区在线观看 | 国产乱国产乱300精品| 日韩电影在线免费看| 午夜免费欧美电影| 天天综合色天天综合色h| 亚洲国产精品久久人人爱| 亚洲精品精品亚洲| 亚洲一区在线观看网站| 亚洲电影一级片| 婷婷国产v国产偷v亚洲高清| 天天综合色天天| 美国十次综合导航| 精品一区二区在线播放| 国产一区二区三区视频在线播放| 精品一区二区三区久久| 精品一区二区三区日韩| 国产一区二区成人久久免费影院 | 青娱乐精品视频| 毛片av一区二区三区| 韩国精品一区二区| 国产精品2024| 91婷婷韩国欧美一区二区| 色综合一个色综合亚洲| 欧美综合亚洲图片综合区| 欧美日韩dvd在线观看| 日韩一区二区三区在线视频| 欧美成人艳星乳罩| 中文字幕不卡的av| 亚洲综合色噜噜狠狠| 日本中文字幕一区二区有限公司| 免费国产亚洲视频| 成人一道本在线| 欧美色欧美亚洲另类二区| 日韩欧美国产电影| 亚洲少妇中出一区| 免费人成精品欧美精品| 国产成都精品91一区二区三| 91免费精品国自产拍在线不卡| 欧美日韩国产高清一区| 精品国产乱码久久久久久久久| 国产精品久久一级| 日本aⅴ免费视频一区二区三区 | 精品1区2区3区| 久久女同互慰一区二区三区| 亚洲欧美一区二区不卡| 麻豆精品视频在线观看视频| 国产成人精品免费网站| 欧美浪妇xxxx高跟鞋交| 中文字幕在线观看不卡| 日日夜夜免费精品| 菠萝蜜视频在线观看一区| 91精品综合久久久久久| 国产精品丝袜一区| 免费高清在线一区| 91麻豆6部合集magnet| 久久亚洲综合色| 亚洲国产成人91porn| 粉嫩aⅴ一区二区三区四区五区| 777xxx欧美| 一区二区三区四区蜜桃| 国产酒店精品激情| 91精品欧美福利在线观看| 亚洲乱码中文字幕综合| 国产不卡视频在线观看| 欧美一级片在线观看| 夜夜嗨av一区二区三区| 99久久精品国产精品久久| 亚洲精品一区二区三区香蕉| 午夜精品福利视频网站| 91麻豆123| 亚洲欧美激情一区二区| 丁香婷婷综合激情五月色| 日韩精品中文字幕一区 | 777a∨成人精品桃花网| 亚洲一区二区在线观看视频| 成人视屏免费看| 久久久久久久久99精品| 精品一区二区精品| 欧美电视剧在线看免费| 视频一区二区三区入口| 色噜噜狠狠色综合欧洲selulu| 国产精品国产三级国产三级人妇 | 欧美一区二区三区免费大片 | 激情五月激情综合网| 日韩一级片在线观看| 日本成人超碰在线观看| 9191久久久久久久久久久| 亚洲第一会所有码转帖| 欧美色手机在线观看| 亚洲18女电影在线观看| 欧美日韩和欧美的一区二区| 午夜成人免费电影|