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


C++ KData::removeSpaces方法代码示例

本文整理汇总了C++中KData::removeSpaces方法的典型用法代码示例。如果您正苦于以下问题:C++ KData::removeSpaces方法的具体用法?C++ KData::removeSpaces怎么用?C++ KData::removeSpaces使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KData的用法示例。


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

示例1: getHttpFileMemory

int KHttp::getHttpFileMemory(const KData& server, const KData& httpfile,
		char** ppKData)
{
	char* pKData = NULL;
	KData httpRequest = "GET ";
	httpRequest += httpfile;
	httpRequest += " HTTP/1.1";
	httpRequest += CRLF;
	httpRequest += "Host: ";
	httpRequest += server;
	httpRequest += CRLF;
	httpRequest += CRLF;
	unsigned char buff[MTU];
	KTcpClientSocket clientSock(server, 80);
	clientSock.connect();
	KConnection &conn = clientSock.getConn();
	string stringTmp = httpRequest.getData();
	conn.writeData(stringTmp);
	int iRead = 0;
	bool bFound = false;
	KData dtHead;
	int iLength = 0;
	int iWrite = 0;
	int m_iStatusCode = 0;
	bool bRun = true;
	while ((iRead = conn.readn(buff, MTU)) > 0 && bRun)
	{
		if (!bFound)
		{
			for (int i = 0; i < iRead - 4; i++)
			{
				if (buff[i] == 0x0d && buff[i + 1] == 0x0a
						&& buff[i + 2] == 0x0d && buff[i + 3] == 0x0a)
				{
					KData dtLine;
					dtHead = KData((char*) buff, i + 4);
					KData dtRequestLine, dtCode;

					if (NOT_FOUND == dtHead.match(CRLF, &dtRequestLine, false))
					{
						return -1;
					}
					if (NOT_FOUND == dtRequestLine.match("HTTP/1.1", NULL, true)
							&& NOT_FOUND
									== dtRequestLine.match("HTTP/1.0", NULL,
											true))
					{
						return -1;
					}
					if (NOT_FOUND == dtRequestLine.match(SP, NULL, true))
					{
						return -1;
					}
					if (NOT_FOUND == dtRequestLine.match(SP, &dtCode, true))
					{
						return -1;
					}
					if ((int) dtCode == 0 && (int) dtCode != 200)
					{
						return -1;
					}

					while (NOT_FOUND != dtHead.match(CRLF, &dtLine, true))
					{
						KData dtBefVal;
						if (FOUND == dtLine.match(":", &dtBefVal, true))
						{
							dtBefVal.removeSpaces();
							if (isEqualNoCase(dtBefVal, "Content-Length"))
							{
								dtLine.removeSpaces();
								iLength = (int) dtLine;
							}
						}
						else if (NOT_FOUND
								!= dtLine.match("HTTP/1.1", NULL, true))
						{
							dtLine.removeSpaces();
							dtLine.match(" ", &dtBefVal, true);
							m_iStatusCode = (int) dtBefVal;
						}

					}
					if (iLength <= 0)
					{
						return -1;
					}
					else if (m_iStatusCode != 200)
					{
						return -1;
					}
					else
					{
						pKData = new char[iLength];
					}

					memcpy(pKData, &buff[i + 4], iRead - i - 4);
					iWrite += (iRead - i - 4);
					bFound = true;

//.........这里部分代码省略.........
开发者ID:korman,项目名称:Temp,代码行数:101,代码来源:KHttp.cpp

示例2: getHttpFileLength


//.........这里部分代码省略.........
	httpRequest += CRLF;
	httpRequest += "Host: ";
	httpRequest += server;
	httpRequest += CRLF;
	httpRequest += "Accept: */*";
	httpRequest += CRLF;
	if (!m_dtUserAgent.isEmpty())
	{
		httpRequest += "User-Agent: ";
		httpRequest += m_dtUserAgent;
		httpRequest += CRLF;
	}

	httpRequest += "Pragma: no-cache";
	httpRequest += CRLF;
	httpRequest += "Cache-Control: no-cache";
	httpRequest += CRLF;
	httpRequest += "Connection: close";
	httpRequest += CRLF;

	if (!bGet)
	{
		httpRequest += "Content-Type: application/x-www-form-urlencoded";
		httpRequest += CRLF;
		httpRequest += "Content-Length: ";
		httpRequest += KData((int) dtPost.length());
		httpRequest += CRLF;
	}

	httpRequest += CRLF;

	char buff[MTU] =
	{ 0 };

	m_clientSock.setServer(server, 80);
	if (!m_clientSock.connect())
	{
		return 0;
	}

	m_kCnnect = m_clientSock.getConn();
	m_kCnnect.setTimeout(m_timeout);

	if (m_kCnnect.writeData(httpRequest) != (int) httpRequest.length())
		return 0;
	m_iWritedBytes += httpRequest.length();

	if (!bGet)
	{
		if (m_kCnnect.writeData(dtPost) != (int) dtPost.length())
			return 0;
		m_iWritedBytes += dtPost.length();
	}

	int iRead;
	m_iStatusCode = 0;

	memset(buff, 0, MTU);

	if ((iRead = m_kCnnect.readLine(buff, MTU)) <= 0)
	{
		m_iReadedBytes += iRead;
		return 0;
	}

	KData dtKData;
	KData dtLine(buff, iRead);
	if (dtLine.match(SP, &dtKData, true) == NOT_FOUND)
	{
		return 0;
	}
	if (dtKData != "HTTP/1.1" && dtKData != "HTTP/1.0")
	{
		return 0;
	}
	if (dtLine.match(SP, &dtKData, true) == NOT_FOUND)
	{
		return 0;
	}
	m_iStatusCode = (int) dtKData;

	while ((iRead = m_kCnnect.readLine(buff, MTU)) > 0)
	{
		m_iReadedBytes += iRead;
		KData dtLine(buff, iRead);

		KData dtBefVal;
		if (FOUND == dtLine.match(":", &dtBefVal, true))
		{
			dtBefVal.removeSpaces();
			dtLine.removeSpaces();
			if (isEqualNoCase(dtBefVal, "Content-Length"))
			{
				return (int) dtLine;
			}
		}
	}

	return 0;
}
开发者ID:korman,项目名称:Temp,代码行数:101,代码来源:KHttp.cpp

示例3: getHttpFile


//.........这里部分代码省略.........
	}

	KData dtKData;
	KData dtLine(szBuffer, iRead);

	if (dtLine.match(SP, &dtKData, true) == NOT_FOUND)
	{
		LOGERROR("Read command line mactch space err" );
		return 0;
	}
	if (dtKData != "HTTP/1.1" && dtKData != "HTTP/1.0")
	{
		LOGERROR( "GET HTTP HEAD ERR" );
		return 0;
	}
	if (dtLine.match(SP, &dtKData, true) == NOT_FOUND)
	{
		LOGERROR("Read command line mactch space 2 err" );
		return 0;
	}

	m_iStatusCode = (int)dtKData;

	LOGD("Ready to while ( (iRead = m_conn.readLine(buff,MTU)) > 0 )");

	while ((iRead = m_kCnnect.readLine(szBuffer, MTU)) > 0)
	{
		m_iReadedBytes += iRead;
		KData dtLine(szBuffer, iRead);

		KData dtBefVal;
		if (FOUND == dtLine.match(":", &dtBefVal, true))
		{
			dtBefVal.removeSpaces();
			dtLine.removeSpaces();

			if (isEqualNoCase(dtBefVal, "Content-Length"))
			{
				m_iLength = (int) dtLine + nStartPos;
				if (m_iNotifyPercent > 0 && m_iNotifyPercent <= 100)
				{
					m_iNotifyPos = m_iNotifyGap = m_iLength
							/ (100 / m_iNotifyPercent);
				}
			}
			else if (isEqualNoCase(dtBefVal, "Transfer-Encoding"))
			{
				if (isEqualNoCase(dtLine, "chunked"))
				{
					m_bChunked = true;
				}
			}
			_respHeadMap[dtBefVal] = dtLine;
		}
	}

	if (iRead < 0)
	{
		LOGERROR("read err" );
		return -1;
	}

	if (m_iStatusCode != 200 && m_iStatusCode != 206)
	{
		if (m_iStatusCode == 302)
		{
开发者ID:korman,项目名称:Temp,代码行数:67,代码来源:KHttp.cpp


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