本文整理汇总了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);
}
}
示例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();
}
示例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);
}
示例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());
}
示例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;
}