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


C++ HttpResponse::getContent方法代码示例

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


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

示例1: parseHttpResponse

void HttpProtocol::parseHttpResponse(const std::string& res,HttpResponse& http)
{
	string response(res);
	int pos;
	if( (pos = res.find("\n\r"))!= -1)
		response = response.replace(pos,2,"\n\n");
	HttpHeader header;
	http.getHeader(header);
	string str(response);
	string delim = "\n";
	vector<string> vec;
	split(str,delim,vec);
	parseResponseLine(vec[0],http);
	int i = 1;
	while(vec[i] != "")
	{
		parseHeader(vec[i],header);
		i++;
	}
	i++;
	for(;i<vec.size();i++)
	{
		string tmp(http.getContent());
		tmp = tmp+vec[i];
		if(i != vec.size()-1)
			tmp+="\n";
		http.setContent(tmp);
	}	
}
开发者ID:Mich-Teng,项目名称:Http-Parser-Generator,代码行数:29,代码来源:HttpProtocol.cpp

示例2: geneHttpResponse

void HttpProtocol::geneHttpResponse(const HttpResponse& http,string& response)
{
	HttpHeader header;
	http.getHeader(header);
	char t[10];
	sprintf(t, "%d", http.getStatusCode());
	string code = t;
	response = "" + http.getVersion() + " " + code + " " +  http.getReason() + "\n";
	geneHeader(response,header);
	response += http.getContent();
}
开发者ID:Mich-Teng,项目名称:Http-Parser-Generator,代码行数:11,代码来源:HttpProtocol.cpp

示例3: string

std::string spider::PageDownloader::getContent(HttpResponse & response) const {
    using std::istream;
    using std::istream_iterator;
    using std::noskipws;
    using std::string;

    istream & stream = response.getContent();
    stream >> noskipws;
    istream_iterator<char> begin(stream);
    istream_iterator<char> end;
    return string(begin, end);
}
开发者ID:jehugaleahsa,项目名称:spider-cpp,代码行数:12,代码来源:page_downloader.cpp

示例4: write

void HttpSocket::write(const HttpResponse& response) {
    std::cout << "Writing in HTTP socket." << std::endl;
    tcp_socket->write(response.header.toStdString().data(), response.header.toStdString().size());
    tcp_socket->write(response.getContent(), response.getContentSize());
}
开发者ID:AmirMuratov,项目名称:CppCW,代码行数:5,代码来源:HttpSocket.cpp

示例5: handle_input

int ClientService::handle_input(ACE_HANDLE fd /* = ACE_INVALID_HANDLE */) {
	if ( fd != get_handle() ) {
		ND_DEBUG("[HTTP][Conn %07d] Received input for unmanaged handle.\n");
		return 0;
	}

	ssize_t recv_cnt;

	// ACE_Time_Value zeroTime(ACE_Time_Value::zero);
/*
	while ( (recv_cnt = sock_.recv(buffer_, buflen_)) > 0 ) {
		ND_DEBUG("[HTTP][Conn %07d] Received %d octets of request data.\n", _connectionNumber, recv_cnt);
		req_.addData(buffer_, recv_cnt);
	}

	int closeErr = errno;
	if (recv_cnt < 0 && closeErr != EWOULDBLOCK) {
		ND_DEBUG("[HTTP][Conn %07d] Connection closed to %s. %p.\n", _connectionNumber, peer_name_, "Reason");
		req_.clear();
		return -1;
	}
*/
	if ( (recv_cnt = sock_.recv(buffer_, buflen_)) < 1 ) {
		ND_DEBUG("[HTTP][Conn %07d] Connection closed to %s. %p.\n", _connectionNumber, peer_name_, "Reason");
		req_.clear();
		return -1;
	}

	ND_DEBUG("[HTTP][Conn %07d] Received %d octets of request data.\n", _connectionNumber, recv_cnt);
	req_.addData(buffer_, recv_cnt);

	// std::string reqStr(req_.getAsString());

	try {
		req_.parse();
	}
	catch (const nd_error& e) {
		ND_CRITICAL("[HTTP][Conn %07d] %s\n", _connectionNumber, e.what());
		req_.clear();
		return 0;
	}

	// ND_DEBUG("[HTTP][Conn %07d] Received %d-octet request:\n%s\n", _connectionNumber, req_.getRequestLength(), reqStr.c_str());

	if (req_.isComplete()) {
		HttpResponse response;

		httpManager::instance()->handleRequest(req_, response);

		string responseStr = response.makeClientStr((req_.getMethod() != HttpRequest::MethodHEAD));
		ND_DEBUG("[HTTP][Conn %07d] Sending response (%d %s, %s, %d octet contents).\n", _connectionNumber,
			response.getStatusCode(),
			response.getStatusStr().c_str(),
			response.getContentType().c_str(),
			response.getContent().length());

		sock_.send(responseStr.c_str(), responseStr.length());

		double ver = req_.getProtocolVersion();
		req_.clear();

		if ( ver == 1.0 ) {
			ND_DEBUG("[HTTP][Conn %07d] Closing HTTP 1.0 connection.\n", _connectionNumber);
			return -1;
		}
	}
	else {
		if ( req_.hasContent() )
			ND_DEBUG("[HTTP][Conn %07d] Received %d octets of %d expected, waiting for more.\n", _connectionNumber,
				req_.getContentLength(), req_.getReportedContentLength());
	}

	return 0;
}
开发者ID:E-LLP,项目名称:channel-emulator,代码行数:74,代码来源:ClientService.cpp


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