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. ubuntu16.4 环境移植ubuntu到zynqMp_zcu102

    安装petalinux 下载petalinux https://www.xilinx.com/support/download 下载 zcu102 ZCU102 BSP 安装petaLinux 把sh ...

  2. 61 (OC)* 代理 block 通知 代理 kvo

    1.从源头上理解和区别block和delegate delegate运行成本低,block的运行成本高. block出栈需要将使用的数据从栈内存拷贝到堆内存,当然对象的话就是加计数,使用完或者bloc ...

  3. scrapy和scrapy-redis的区别

    scrapy是一个python爬虫框架,爬取的效率极高,具有高度的定制性,但是不支持分布式.而scrapy-redis是一套基于redis库,运行在scrapy框架之上的组件,可以让scapy支持分布 ...

  4. Spotlight性能监控工具的配置及使用

    这是我离线整理资料里的内容,大概是2012年时候开始使用此性能监控工具的,直到至今,接触到几个性能监控工具里,还是美国quest公司生产的Spotlight此产品相对比较牛! 我也不知道现在发展到能支 ...

  5. 23种设计模式之工厂方法(Factory Method Pattern)

    工厂方法 前面我们学习了简单工厂,发现一个问题就是简单工厂集合了矛盾,为了解决这个问题我们针对每一种产品提供一个工厂类.通过不同的工厂实例来创建不同的产品实例.在同一等级结构中,支持增加任意产品这种设 ...

  6. Enum枚举的使用实现

    业务中涉及到的状态字段或者简单的选择项的使用. 例如: 1.定义enum枚举类. package com.yjl.enums; import java.util.Objects; public enu ...

  7. Angular ngx-echarts图表

    1. 安装echarts包.ngx-echarts包 npm install echarts --save npm install ngx-echarts --save 2. angular.json ...

  8. 【转】ICMP协议

    1.ICMP出现的原因 在IP通信中,经常有数据包到达不了对方的情况.原因是,在通信途中的某处的一个路由器由于不能处理所有的数据包,就将数据包一个一个丢弃了.或者,虽然到达了对方,但是由于搞错了端口号 ...

  9. spring源码分析系列4:ApplicationContext研究

    ApplicationContext接口 首先看一下一个最基本的上下文应该是什么样子 ApplicationContext接口的注释里写的很清楚: 一个基本applicationContext应该提供 ...

  10. 安装sublime插件安装不上遇到的各种坑

    为了学习VUE , 发现没有高亮代码, 百度原来需要安装插件,安装过程中遇到了各种坑,记录下来避免大家踩坑, 首先用代码安装快捷键  ctrl+`   粘贴代码 import urllib.reque ...