示例#1
0
void CXmlDocument::ToString(CDataBuffer& buffer)
{
	TiXmlPrinter printer;
	printer.SetLineBreak("\r\n");
	printer.SetIndent("\t");
	_doc->Accept(&printer);
	buffer.Add(printer.CStr());
}
示例#2
0
void CHttpRequest::Finalize(CDataBuffer& raw_request)
{
	raw_request.Clear();

	if(!IsHeaderExist(CONTENT_LENGTH_HEADER)){
		CHttpHeader content_length;
		content_length.SetName(CONTENT_LENGTH_HEADER);
		content_length.SetValue(CString(_content.GetLength()));
		AddHeader(content_length);
	}

	if (_method == GET_M){
		raw_request += HTTP_METHOD_GET_STR;
	}
	else if (_method == POST_M){
		raw_request += HTTP_METHOD_POST_STR;
	}
	else{
		throw CEIBException(HttpProtocolError,"Http Method not defined.");
	}
	raw_request += SPACE;
	raw_request += _request_uri;
	
	//parameters section
	if(_params.size() > 0){
		raw_request += QUERY_STRING_SEPERATOR;
	}

	map<CString,CHttpParameter>::iterator params_it;
	for(params_it = _params.begin(); params_it != _params.end(); ++params_it)
	{
		raw_request += params_it->second.GetName();
		raw_request += PARAMETER_SEPERATOR;
		raw_request += params_it->second.GetValue();
	}

	raw_request += SPACE;

	if (_version == HTTP_1_0){
		raw_request += HTTP_1_0_STR;
	}
	else if (_version == HTTP_1_1){
		raw_request += HTTP_1_0_STR;
	}
	else{
		throw CEIBException(HttpProtocolError,"Http version not defined.");
	}
	raw_request += CRLF;

	map<CString,CHttpHeader>::iterator it;
	for(it = _headers.begin(); it != _headers.end(); ++it)
	{
		raw_request += it->second.GetName();
		raw_request += HEADER_SEPERATOR;
		raw_request += SPACE;
		raw_request += it->second.GetValue();
		raw_request += CRLF;
	}

	if (_content.GetLength() > 0){
		raw_request += CRLF;
		raw_request.Add(_content.GetBuffer(),_content.GetLength());
	}

	raw_request += CRLF;
	raw_request += CRLF;
}