本文整理汇总了C++中HTTPResponse::getPartAsString方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPResponse::getPartAsString方法的具体用法?C++ HTTPResponse::getPartAsString怎么用?C++ HTTPResponse::getPartAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPResponse
的用法示例。
在下文中一共展示了HTTPResponse::getPartAsString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
ReadResult
HTTPClient::doReadString(const HTTPRequest& request,
const osgDB::Options* options,
ProgressCallback* callback )
{
initialize();
ReadResult result;
HTTPResponse response = this->doGet( request, options, callback );
if ( response.isOK() )
{
result = ReadResult( new StringObject(response.getPartAsString(0)) );
}
else if ( response.getCode() >= 400 && response.getCode() < 500 && response.getCode() != 404 )
{
// for request errors, return an error result with the part data intact
// so the user can parse it as needed. We only do this for readString.
result = ReadResult(
ReadResult::RESULT_SERVER_ERROR,
new StringObject(response.getPartAsString(0)) );
}
else
{
result = ReadResult(
response.isCancelled() ? ReadResult::RESULT_CANCELED :
response.getCode() == HTTPResponse::NOT_FOUND ? ReadResult::RESULT_NOT_FOUND :
response.getCode() == HTTPResponse::SERVER_ERROR ? ReadResult::RESULT_SERVER_ERROR :
response.getCode() == HTTPResponse::NOT_MODIFIED ? ReadResult::RESULT_NOT_MODIFIED :
ReadResult::RESULT_UNKNOWN_ERROR );
//If we have an error but it's recoverable, like a server error or timeout then set the callback to retry.
if (HTTPClient::isRecoverable( result.code() ) )
{
if (callback)
{
if ( s_HTTP_DEBUG )
{
OE_NOTICE << LC << "Error in HTTPClient for " << request.getURL() << " but it's recoverable" << std::endl;
}
callback->setNeedsRetry( true );
}
}
}
// encode headers
result.setMetadata( response.getHeadersAsConfig() );
// last-modified (file time)
result.setLastModifiedTime( getCurlFileTime(_curl_handle) );
return result;
}
示例2: if
ReadResult
HTTPClient::doReadString(const std::string& location,
const osgDB::Options* options,
ProgressCallback* callback )
{
initialize();
ReadResult result;
HTTPResponse response = this->doGet( location, options, callback );
if ( response.isOK() )
{
result = ReadResult( new StringObject(response.getPartAsString(0)), response.getHeadersAsConfig());
}
else if ( response.getCode() >= 400 && response.getCode() < 500 && response.getCode() != 404 )
{
// for request errors, return an error result with the part data intact
// so the user can parse it as needed. We only do this for readString.
result = ReadResult(
ReadResult::RESULT_SERVER_ERROR,
new StringObject(response.getPartAsString(0)),
response.getHeadersAsConfig() );
}
else
{
result = ReadResult(
response.isCancelled() ? ReadResult::RESULT_CANCELED :
response.getCode() == HTTPResponse::NOT_FOUND ? ReadResult::RESULT_NOT_FOUND :
response.getCode() == HTTPResponse::SERVER_ERROR ? ReadResult::RESULT_SERVER_ERROR :
ReadResult::RESULT_UNKNOWN_ERROR );
//If we have an error but it's recoverable, like a server error or timeout then set the callback to retry.
if (HTTPClient::isRecoverable( result.code() ) )
{
if (callback)
{
OE_DEBUG << "Error in HTTPClient for " << location << " but it's recoverable" << std::endl;
callback->setNeedsRetry( true );
}
}
}
// last-modified (file time)
TimeStamp filetime = 0;
if ( CURLE_OK == curl_easy_getinfo(_curl_handle, CURLINFO_FILETIME, &filetime) )
{
result.setLastModifiedTime( filetime );
}
return result;
}
示例3: initialize
ReadResult
HTTPClient::doReadString(const std::string& location,
const osgDB::Options* options,
ProgressCallback* callback )
{
initialize();
ReadResult result;
HTTPResponse response = this->doGet( location, options, callback );
if ( response.isOK() )
{
result = ReadResult( new StringObject(response.getPartAsString(0)), response.getHeadersAsConfig());
}
else
{
result = ReadResult(
response.isCancelled() ? ReadResult::RESULT_CANCELED :
response.getCode() == HTTPResponse::NOT_FOUND ? ReadResult::RESULT_NOT_FOUND :
response.getCode() == HTTPResponse::SERVER_ERROR ? ReadResult::RESULT_SERVER_ERROR :
ReadResult::RESULT_UNKNOWN_ERROR );
//If we have an error but it's recoverable, like a server error or timeout then set the callback to retry.
if (HTTPClient::isRecoverable( result.code() ) )
{
if (callback)
{
OE_DEBUG << "Error in HTTPClient for " << location << " but it's recoverable" << std::endl;
callback->setNeedsRetry( true );
}
}
}
return result;
}
示例4: createFeatureCursor
//override
FeatureCursor* createFeatureCursor( const Symbology::Query& query )
{
std::string url = createURL( query );
HTTPResponse response = HTTPClient::get(url);
FeatureList features;
if (response.isOK())
{
getFeatures(response, features);
std::string data = response.getPartAsString(0);
}
else
{
OE_INFO << "Error getting url " << url << std::endl;
}
return new FeatureListCursor( features );
}
示例5: input
HTTPClient::ResultCode
HTTPClient::doReadString(const std::string& filename,
std::string& output,
ProgressBase* callback )
{
ResultCode result = RESULT_OK;
if ( osgDB::containsServerAddress( filename ) )
{
HTTPResponse response = this->doGet( filename, NULL, callback );
if ( response.isOK() )
{
output = response.getPartAsString( 0 );
}
else
{
result =
response.isCancelled() ? RESULT_CANCELED :
response.getCode() == HTTPResponse::NOT_FOUND ? RESULT_NOT_FOUND :
response.getCode() == HTTPResponse::SERVER_ERROR ? RESULT_SERVER_ERROR :
RESULT_UNKNOWN_ERROR;
//If we have an error but it's recoverable, like a server error or timeout then set the callback to retry.
if (HTTPClient::isRecoverable( result ) )
{
if (callback)
{
//OE_DEBUG << "Error in HTTPClient for " << filename << " but it's recoverable" << std::endl;
callback->setNeedsRetry( true );
}
}
}
}
else
{
std::ifstream input( filename.c_str() );
if ( input.is_open() )
{
input >> std::noskipws;
std::stringstream buf;
buf << input.rdbuf();
std::string bufStr;
bufStr = buf.str();
output = bufStr;
}
else
{
示例6:
URIStream::URIStream( const URI& uri ) :
_fileStream( 0L )
{
if ( osgDB::containsServerAddress(uri.full()) )
{
HTTPResponse res = HTTPClient::get( uri.full() );
if ( res.isOK() )
{
std::string buf = res.getPartAsString(0);
_bufStream.str(buf);
}
}
else
{
_fileStream = new std::ifstream( uri.full().c_str() );
}
}
示例7:
URIStream::URIStream(const URI& uri, std::ios_base::openmode mode) :
_instream( 0L )
{
if ( osgDB::containsServerAddress(uri.full()) )
{
HTTPResponse res = HTTPClient::get( uri.full() );
if ( res.isOK() )
{
std::string buf = res.getPartAsString(0);
_instream = new std::istringstream(buf);
}
}
else
{
_instream = new std::ifstream(uri.full().c_str(), mode);
}
}
示例8: getFeatures
void getFeatures(HTTPResponse &response, FeatureList& features)
{
//OE_NOTICE << "mimetype=" << response.getMimeType() << std::endl;
//TODO: Handle more than just geojson...
std::string ext = getExtensionForMimeType(response.getMimeType());
//Save the response to a temp file
std::string tmpPath = getTempPath();
std::string name = getTempName(tmpPath, ext);
saveResponse(response, name );
//OE_NOTICE << "Saving to " << name << std::endl;
//OGRDataSourceH ds = OGROpen(name.c_str(), FALSE, &driver);
OGRDataSourceH ds = OGROpen(name.c_str(), FALSE, NULL);
if (!ds)
{
OE_NOTICE << "Error opening data with contents " << std::endl
<< response.getPartAsString(0) << std::endl;
}
OGRLayerH layer = OGR_DS_GetLayer(ds, 0);
//Read all the features
if (layer)
{
OGR_L_ResetReading(layer);
OGRFeatureH feat_handle;
while ((feat_handle = OGR_L_GetNextFeature( layer )) != NULL)
{
if ( feat_handle )
{
Feature* f = OgrUtils::createFeature( feat_handle );
if ( f )
{
features.push_back( f );
}
OGR_F_Destroy( feat_handle );
}
}
}
//Destroy the datasource
OGR_DS_Destroy( ds );
//Remove the temporary file
remove( name.c_str() );
}