本文整理汇总了C++中HTTPResponse::getDate方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPResponse::getDate方法的具体用法?C++ HTTPResponse::getDate怎么用?C++ HTTPResponse::getDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPResponse
的用法示例。
在下文中一共展示了HTTPResponse::getDate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: downloadURL
bool ofxSimpleHttp::downloadURL(ofxSimpleHttpResponse* resp, bool sendResultThroughEvents, bool beingCalledFromMainThread, bool saveToDisk){
bool ok;
ofstream myfile;
bool fileIsAlreadyHere = false;
//create a file to save the stream to
if(saveToDisk){
if (resp->expectedChecksum.length()){ //if user provided a checksum
ofFile f;
f.open(resp->absolutePath);
if (f.exists()){
fileIsAlreadyHere = ofxChecksum::sha1(resp->absolutePath, resp->expectedChecksum);
if(fileIsAlreadyHere){
resp->checksumOK = true;
resp->status = 0;
resp->ok = true;
resp->fileWasHere = true;
ofLogVerbose() << "ofxSimpleHttp: about to download "<< resp->url << " but a file with same name and correct checksum is already here!";
ofLogVerbose() << "ofxSimpleHttp: skipping download (" << resp->expectedChecksum << ")";
}
}
f.close();
}else{
if (!onlySkipDownloadIfChecksumMatches){
ofFile f;
f.open(resp->absolutePath);
if (f.exists() && f.getSize() > 0){
resp->checksumOK = false;
resp->status = 0;
resp->ok = true;
resp->fileWasHere = true;
fileIsAlreadyHere = true;
ofLogVerbose() << "ofxSimpleHttp: about to download "<< resp->url << " but a file with same name and (size > 0) is already here!";
ofLogVerbose() << "ofxSimpleHttp: skipping download (missing checksum)";
}
f.close();
}
}
}
if (!fileIsAlreadyHere){ //if file is not here, download it!
myfile.open( resp->absolutePath.c_str(), ios_base::binary );
//myfile.open(ofToDataPath(filename).c_str()); //for not binary?
try {
ofHttpRequest request(resp->url, resp->url);
URI uri(request.url);
std::string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
HTTPClientSession * session;
if(uri.getScheme()=="https"){
session = new HTTPSClientSession(uri.getHost(), uri.getPort());//,context);
}else{
session = new HTTPClientSession(uri.getHost(), uri.getPort());
}
//resp->session = &session;
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
req.set( "User-Agent", userAgent.c_str() );
session->setTimeout( Poco::Timespan(timeOut,0) );
session->sendRequest(req);
HTTPResponse res;
istream& rs = session->receiveResponse(res);
resp->status = res.getStatus();
try {
resp->timestamp = res.getDate();
} catch (Exception& exc) {
resp->timestamp = 0;
}
resp->reasonForStatus = res.getReasonForStatus( res.getStatus() );
resp->contentType = res.getContentType();
resp->serverReportedSize = res.getContentLength();
resp->timeTakenToDownload = ofGetElapsedTimef();
if (resp->serverReportedSize == -1) ofLogWarning("ofxSimpleHttp", "downloadURL(%s) >> Server doesn't report download size...", resp->fileName.c_str() );
ofLogVerbose("ofxSimpleHttp", "downloadURL() >> about to start download (%s, %d bytes)", resp->fileName.c_str(), res.getContentLength() );
ofLogVerbose("ofxSimpleHttp", "downloadURL() >> server reports request status: (%d-%s)", resp->status, resp->reasonForStatus.c_str() );
//StreamCopier::copyStream(rs, myfile); //write to file here!
if(saveToDisk){
streamCopyWithProgress(rs, myfile, resp->serverReportedSize, resp->downloadProgress, resp->downloadSpeed, resp->downloadCanceled);
}else{
copyToStringWithProgress(rs, resp->responseBody, resp->serverReportedSize, resp->downloadProgress, resp->downloadSpeed, resp->downloadCanceled);
}
resp->timeTakenToDownload = ofGetElapsedTimef() - resp->timeTakenToDownload;
if (resp->expectedChecksum.length() > 0){
resp->checksumOK = ofxChecksum::sha1(resp->absolutePath, resp->expectedChecksum);
//.........这里部分代码省略.........