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 \n", strFilePath.c_str()); string strFileName = DPC::get_FileName_path(strUrl, "/");
strFileName = "attachment; filename=" + strFileName; //查看文件是否存在
if (access(strFilePath.c_str(), ) == -)
{
evhttp_send_error(req, HTTP_BADREQUEST, );
return;
}
//=========
std::ifstream t;
t.open(strFilePath.c_str(), ios::in | ios::binary);
t.seekg(, std::ios::end);
long length = t.tellg();
t.seekg(, std::ios::beg); char *buffer = new char[length];
t.read(buffer, length);
t.close(); char FileSize[] = { '\0' };
snprintf(FileSize, sizeof(FileSize), "%d", length); time_t timep;
time(&timep);
char s[];
sprintf(s, ctime(&timep));
std::string strDate = std::string(s, s + (strlen(s) - ));
evhttp_add_header(evhttp_request_get_output_headers(req), "Server", "Unix");
evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Type", "application/octet-stream; charset=utf-8");
evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Disposition", strFileName.c_str());
evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Length", FileSize);
evhttp_add_header(evhttp_request_get_output_headers(req), "Date", strDate.c_str());
evhttp_add_header(evhttp_request_get_output_headers(req), "Connection", "close");
//========= //回响应
struct evbuffer *retbuff = NULL;
retbuff = evbuffer_new();
if (retbuff == NULL)
{
return;
}
evbuffer_add(retbuff, buffer, length);
//evbuffer_add_printf(retbuff, "123");
evhttp_send_reply(req, HTTP_OK, "Client", retbuff);
evbuffer_free(retbuff);
}

Libevent::evhttp服务器下载的更多相关文章

  1. Libevent::evhttp服务器

    #include <cstdio> #include <stdio.h> #include <stdlib.h> #include <string.h> ...

  2. 【FTP】C# System.Net.FtpClient库连接ftp服务器(下载文件)

    如果自己单枪匹马写一个连接ftp服务器代码那是相当恐怖的(socket通信),有一个评价较高的dll库可以供我们使用. 那就是System.Net.FtpClient,链接地址:https://net ...

  3. (4)FTP服务器下载文件

    上一篇中,我们提到了怎么从FTP服务器下载文件.现在来具体讲述一下. 首先是路径配置.. 所以此处我们需要一个app.config来设置路径. <?xml version="1.0&q ...

  4. AssetBundle实现服务器下载并从本地读取

    废话不多说  直接上代码. 从服务器下载的, 很简单 private IEnumerator Start() { byte[] ab = null; int len = 0; WWW www =nul ...

  5. Python 实现批量从不同的Linux服务器下载文件

    基于Python实现批量从不同的Linux服务器下载文件   by:授客 QQ:1033553122 实现功能 1 测试环境 1 使用方法 1 1. 编辑配置文件conf/file_for_downl ...

  6. 2.4 利用FTP服务器下载和上传目录

    利用FTP服务器下载目录 import os,sys from ftplib import FTP from mimetypes import guess_type nonpassive = Fals ...

  7. java后台中处理图片辅助类汇总(上传图片到服务器,从服务器下载图片保存到本地,缩放图片,copy图片,往图片添加水印图片或者文字,生成二维码,删除图片等)

    最近工作中处理小程序宝箱活动,需要java画海报,所以把这块都快百度遍了,记录一下处理的方法,百度博客上面也有不少坑! 获取本地图片路径: String bgPath = Thread.current ...

  8. 从Linux服务器下载文件到本地命令

    从Linux服务器下载文件夹到本地1.使用scp命令 scp /home/work/source.txt work@192.168.0.10:/home/work/ #把本地的source.txt文件 ...

  9. Android----- 版本更新和 服务器下载新版本APK并安装

    前段时间有朋友问我版本更新的问题,所以来写一篇版本更新和APK下载并安装的博客. 版本更新,几乎在所有的项目中都用的到,一般是这样的流程,当进入APP首页是便会检测版本是否为最新版本,不是则提示你下载 ...

随机推荐

  1. Nightmare Ⅱ(双向BFS)

    Problem Description Last night, little erriyue had a horrible nightmare. He dreamed that he and his ...

  2. Uva 232 一个换行WA 了四次

    由于UVA OJ上没有Wrong anwser,搞的多花了好长时间去测试程序,之前一直以为改OJ有WA,后来网上一搜才知道没有WA,哎哎浪费了好长时间.此博客用来记录自己的粗心大意. 链接地址:htt ...

  3. Salesforce学习之路-developer篇(一)利用VS Code结合Git开发Salesforce

    Part 1: 从Git中克隆代码到本地 git clone https://github.com/git/git Part 2: 在VS Code中安装Salesforce和Git插件 在VS Co ...

  4. 提交任务到spark(以wordcount为例)

    1.首先需要搭建好hadoop+spark环境,并保证服务正常.本文以wordcount为例. 2.创建源文件,即输入源.hello.txt文件,内容如下: tom jerry henry jim s ...

  5. 这些Mysql常用命令你是否还记得?

    前言 记录mysql常用命令操作 基础操作 命令行登录mysql  mysql -u用户名 -p用户密码 为表增加创建时间和更新时间 ALTER TABLE order_info_tbl ADD CO ...

  6. Mysql - 关于relay_log_recovery参数的测试

    一.概述 官方文档中对relay_log_recovery参数的解释 Enables automatic relay log recovery immediately following server ...

  7. asp.net core + layui.js 搭建仓储系统

    先放几张网站图片: 第一步先从layui 网站https://www.layui.com/doc/ 下载相关文件,复制到项目 wwwroot 目录下: 然后在 _Layout.cshtml 中引用 l ...

  8. filebeat使用multiline丢失数据问题

    最近部署filebeat采集日志. 发现配置multiline后,日志偶尔会丢失数据,而且采集到的数据长度都不相同,所以和日志长度没有关系. 查阅filebeat官网后,找到了问题.filebeat有 ...

  9. 记一次jmeter从txt文本获取数值并给测试计划的变量赋值,jmeter永久性修改变量。

    前言: 需要永久性的改变变量. 其实这个办法并不是最好的,但是是最容易实现的.后期可做成从数据库里直接取值. 赋值BeanShell import java.io.File; import java. ...

  10. C#控件及常用属性

    1.窗体(Form) 1.常用属性 (1)Name 属性:用来获取或设置窗体的名称,在应用程序中可通过Name 属性来引用窗体. (2) WindowState 属性: 用来获取或设置窗体的窗口状态. ...