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. Java面试-如何获取客户端真实IP

    在进行一些小游戏开发时,我们经常比较关注的一个功能便是分享.针对分享,我们希望能根据各个城市或者地区,能有不同的分享文案,辨识地区的功能如果由服务器来完成的话,我们就需要知道客户端的真实IP.今天我们 ...

  2. CSS——设置背景

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. Qt疑难问题-模态窗口父类被析构

    最近遇到一个朋友,问了我一个刁钻的问题,当你模态弹出一个窗体时,后台把这个窗体的父类给析构了,这个时候会出现什么样的情况? 听到问题后我真是一脸懵逼呀!从来没有这么写过代码. 随后写了一个简单的测试d ...

  4. SpringCloud之Turbine

    [前面的话]书接上文,本文的某些知识依赖我的上一篇SpringCLoud的文章:SpringCloud之Feign,如果没有看过可以先移步去看一下.前文提到了hystrix的应用,以及hystrix的 ...

  5. java架构之路-(mysql底层原理)Mysql之让我们再深撸一次mysql

    让我再深撸一次mysql吧,这次主要以应对面试来说说mysql,大概几个方向,索引结构,查询引擎,索引优化,explain的详解和trace工具的使用. 索引: 我们先来看一下mysql的B+tree ...

  6. Springboot2.1.x配置Activiti7单独数据源问题

    Springboot2.1.x配置Activiti7单独数据源问题 简介 最近基于最新的Activiti7配置了SpringBoot2. 简单上手使用了一番.发现市面上解决Activiti7的教程很少 ...

  7. .NET Core应用的三种部署方式

    .NET Core应用提供了三种部署方式: FDD FDD:Framework-dependent deployment,框架依赖部署.这种方式针对某个特定版本的.NET Core进行发布,只打包应用 ...

  8. 先森林后树木:Elasticsearch各版本升级核心内容必看

    在学习Elasticsearch 时候,因为各个版本的问题,搞不清,非常的头疼,官方也给出了各个版本更新的情况,不过是英文版本,版本更新信息又特别多,最近学习,看了很多资料,没有一个整理很清楚的,然后 ...

  9. sklearn 标准化数据的方法

    Sklearn 标准化数据 from __future__ import print_function from sklearn import preprocessing import numpy a ...

  10. cat命令显示文件指定行

    cat filename | tail -n 100 显示文件最后100行 cat filename | head -n 100 显示文件前面100行 cat filename | tail -n + ...