Libevent::evhttp服务器下载
Posted osbreak
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Libevent::evhttp服务器下载相关的知识,希望对你有一定的参考价值。
void http_handler_Get_Download(struct evhttp_request *req, void *arg) { if (req == NULL) { return; } const char *uri = evhttp_request_get_uri(req); string strUrl(uri); string strFilePath = DPC::get_Url_path(strUrl, "path="); printf("FilePath = %s ", strFilePath.c_str()); string strFileName = DPC::get_FileName_path(strUrl, "/"); strFileName = "attachment; filename=" + strFileName; //查看文件是否存在 if (access(strFilePath.c_str(), 0) == -1) { evhttp_send_error(req, HTTP_BADREQUEST, 0); return; } //========= std::ifstream t; t.open(strFilePath.c_str(), ios::in | ios::binary); t.seekg(0, std::ios::end); long length = t.tellg(); t.seekg(0, std::ios::beg); char *buffer = new char[length]; t.read(buffer, length); t.close(); char FileSize[10] = { ‘