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. IO流——File类(文件流类)

    java语言的输入输出操作是借助于输入输出包java.io来实现的,按传输方向分为输入流与输出流,从外设传递到应用程序的流为输入流,将数据从应用程序输入到外设的流为输出流. File类的构造方法: 1 ...

  2. linux 操作系统级别监控 TOP命令

    Top命令是Linux下一个实时的.交互式的,对操作系统整体监控的命令,可以对CPU.内存.进程监控. 是Linux下最常用的监控命令. 第一行是任务队列信息 1 user 当前登录用户数load a ...

  3. Day 14 查找文件 find

    find 查找方式 1.按照名称进行查找 [root@oldboyedu ~]# find ./ -name "*eth0" 2.按照名称查找(不区分大小写) [root@oldb ...

  4. java线上cpu、内存问题排查方法

    一.线程 查进程中占用cpu高的线程 ps -mp xxxxx -o THREAD,tid,time | sort -rn 将线程的id从10位转到16位,可以在下面jstack中找到对应线程 输出线 ...

  5. Vue学习之vue实例中的数据、事件和方法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 解决commBind: Cannot bind socket FD 18 to [::1]: (99) Cannot assign requested address squid

    最近玩squid主要是为了爬虫代理,但是使用docker搭建squid的时候发现,docker一直默认使用的 ipv6,但是squid使用ipv4,导致无法绑定,出现commBind: Cannot ...

  7. 使用git在github远程仓库中操作

    在github上创建一个仓库,这一步参考廖雪峰老师的git教程,以及其他的一些准备工作略,我只记录几个重要的命令. 从其他github地址克隆项目 $ git clone git@github.com ...

  8. Java查询判断素数实验报告

    实验源代码: package sushu; import java.util.Scanner; public class First { int size=2; int data[]=new int[ ...

  9. mybatis #{}和${}的区别是什么?

    #{}是预编译处理,${}是字符串替换.mybatis在处理#{}时,会将sql中的#{}替换为?号,调用PreparedStatement的set方法来赋值,最后注入进去是带引号的:mybatis在 ...

  10. .Net Core 商城微服务项目系列(八):购物车

    最近加班有点多,一周五天,四天加班到11点+,心很累.原因是我当前在的这个组比较特殊,相当于业务的架构组,要为其它的开发组提供服务和监控.所以最近更新的也少,不过这个元旦三天假应该会更新三篇. 这篇是 ...