本文整理汇总了C++中HttpResponse::append方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpResponse::append方法的具体用法?C++ HttpResponse::append怎么用?C++ HttpResponse::append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse::append方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onRead
void WebClientApp::onRead( ci::BufferRef buffer )
{
mText.push_back(toString( buffer->getSize() ) + " bytes read" );
if ( !mHttpResponse.hasHeader() ) {
mHttpResponse.parseHeader( HttpResponse::bufferToString( buffer ) );
buffer = HttpResponse::removeHeader( buffer );
}
mHttpResponse.append( buffer );
mSession->read();
}
示例2: onRead
void HttpClientApp::onRead( ci::BufferRef buffer )
{
size_t sz = buffer->getSize();
mBytesRead += sz;
mText.push_back( toString( sz ) + " bytes read" );
if ( !mHttpResponse.hasHeader() ) {
// Parse header
mHttpResponse.parseHeader( HttpResponse::bufferToString( buffer ) );
buffer = HttpResponse::removeHeader( buffer );
// Get content-length
for ( const KeyValuePair& kvp : mHttpResponse.getHeaders() ) {
if ( kvp.first == "Content-Length" ) {
mContentLength = fromString<size_t>( kvp.second );
break;
}
}
}
// Append buffer to body
mHttpResponse.append( buffer );
if ( mBytesRead < mContentLength ) {
// Keep reading until we hit the content length
mSession->read();
} else {
mText.push_back( "Read complete" );
mText.push_back( toString( mHttpResponse.getStatusCode() ) + " " + mHttpResponse.getReason() );
if ( mHttpResponse.getStatusCode() == 200 ) {
for ( const KeyValuePair& kvp : mHttpResponse.getHeaders() ) {
// Choose file extension based on MIME type
if ( kvp.first == "Content-Type" ) {
string mime = kvp.second;
if ( mime == "audio/mp3" ) {
mFilename += ".mp3";
} else if ( mime == "image/jpeg" ) {
mFilename += ".jpg";
} else if ( mime == "image/png" ) {
mFilename += ".png";
}
} else if ( kvp.first == "Connection" ) {
// Close connection if requested by server
if ( kvp.second == "close" ) {
mSession->close();
}
}
}
// Save the file
fs::path path = getAppPath();
#if !defined ( CINDER_MSW )
path = path.parent_path();
#endif
path = path / mFilename;
OStreamFileRef file = writeFileStream( path );
file->write( mHttpResponse.getBody() );
mText.push_back( mFilename + " downloaded" );
} else {
// Write error
mText.push_back( "Response: " + HttpResponse::bufferToString( mHttpResponse.getBody() ) );
mSession->close();
}
}
}