pdf下载整理:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net; namespace PdfDownload
{
/// <summary>
/// PDF 下载工具
/// </summary>
public class PDF : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
var url = context.Request["url"];
var title = context.Request["title"];
var response = context.Response;
if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(title))
{
response.Charset = System.Text.Encoding.UTF8.ToString();
response.ContentEncoding = System.Text.Encoding.UTF8;
try
{
HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(url);
request.Timeout = 5000;
request.ReadWriteTimeout = 1000;
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
using (var remoteResponse = request.GetResponse())
{
var length = remoteResponse.ContentLength;
if (length != -1)
{
response.ContentType = "application/pdf";
response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(title));
response.AppendHeader("Content-Length", length.ToString());
byte[] buffer = new byte[512 * 1024];
using (var stream = remoteResponse.GetResponseStream())
{
var position = 0;
while ((position = stream.Read(buffer, 0, buffer.Length)) > 0)
{
response.OutputStream.Write(buffer, 0, position);
}
}
response.Flush();
return;
}
}
}
catch (Exception ex)
{
response.ContentType = "html/text";
System.Text.StringBuilder builder = new System.Text.StringBuilder();
builder.Append("URL:");
builder.AppendLine(url);
builder.AppendLine(ex.ToString());
response.Write(builder.ToString());
}
}
else
{
context.Response.StatusCode = 404;
}
} public string GetWindSessionID(HttpContext context)
{
string str = context.Request.Headers["wind.sessionid"];
if (string.IsNullOrEmpty(str))
{
str = context.Request.QueryString["wind.sessionid"];
if (string.IsNullOrEmpty(str) && (context.Request.Cookies["wind.sessionid"] != null))
{
str = context.Request.Cookies["wind.sessionid"].Value;
}
}
return str;
} public bool IsReusable
{
get
{
return true;
}
}
}
}

  

pdf 下载整理的更多相关文章

  1. MySQL管理之道,性能调优,高可用与监控(第二版)pdf下载

    MySQL管理之道,性能调优,高可用与监控(第二版) 书中内容以实战为导向,所有内容均来自于笔者多年实践经验的总结和新知识的拓展,同时也针对运维人员.DBA等相关工作者会遇到的有代表性的疑难问题给出了 ...

  2. 手机user agent大全下载 整理发布一批移动设备的user agent【分享】

    手机user agent大全下载 整理发布一批移动设备的user agent[分享] 很多人朋友在玩浏览器的时候 或者写软件的时候需要用到 user agent 这个东西 修改这个 可以使自己的浏览器 ...

  3. Spring Boot 系列教程18-itext导出pdf下载

    Java操作pdf框架 iText是一个能够快速产生PDF文件的java类库.iText的java类对于那些要产生包含文本,表格,图形的只读文档是很有用的.它的类库尤其与java Servlet有很好 ...

  4. 肖秀荣8套卷2018pdf下载|2018肖秀荣冲刺8套卷pdf下载电子版

    肖秀荣8套卷2018pdf下载|2018肖秀荣冲刺8套卷pdf下载电子版 下载链接: https://u253469.ctfile.com/fs/253469-229815828

  5. pdf 下载demo

    最近写了个pdf下载的demo,在这里记录一下.. 1  要下载pdf首先要有pdf 模板 ,制作pdf 模板就是 word 另存为 pdf . 2 用 Adobe Acrobat X Pro 这个软 ...

  6. [原]Jenkins(一)---我理解的jenkins是这样的(附全套PDF下载)

    /** * lihaibo * 文章内容都是根据自己工作情况实践得出. *版权声明:本博客欢迎转发,但请保留原作者信息! http://www.cnblogs.com/horizonli/p/5330 ...

  7. 蘑菇街支付架构 PDF 下载

    蘑菇街支付架构 PDF 下载 下载地址:链接:https://pan.baidu.com/s/1ZffetaUhVMOzb9j2PSQJIQ 密码:iays http://www.java1234.c ...

  8. swift user guide.pdf下载

    日志以便日后查找.谢谢 1 Swift User Guide.pdf下载 http://download.csdn.net/detail/swifttrain/7442921 2 The Swift ...

  9. 码书:编码与解码的战争 PDF 下载

    码书:编码与解码的战争 PDF 下载 下载地址:https://pan.baidu.com/s/14Y_krHh-unOv4g2KYFFDgQ 如需分享码:[打开微信]->[扫描右侧二维码]-& ...

随机推荐

  1. Spring学习(2):面向接口编程思想

    一. 引言 Spring核心的IOC的实体用了面向接口编程思想,所以有必要了解下.简单来说的话,Spring就是一个轻量级的控制反转(IOC)和面向切面(AOP)的容器框架. 接口的定义的概念:泛指实 ...

  2. CentOS7使用阿里源安装最新版Docker

    卸载已经安装的Docker sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker ...

  3. 从零开始的Python学习Episode 9——集合

    集合 集合是一个无序的,不重复的数据组合,是python基本的数据类型,把不同的元素组成一起就形成集合. 一.创建集合 s = set('smile')list = ['1','2','3']prin ...

  4. tensorflow中使用mnist数据集训练全连接神经网络-学习笔记

    tensorflow中使用mnist数据集训练全连接神经网络 ——学习曹健老师“人工智能实践:tensorflow笔记”的学习笔记, 感谢曹老师 前期准备:mnist数据集下载,并存入data目录: ...

  5. git blame 查看某行代码提交记录

    1. 在当前git项目目录下执行 git blame -L 38,38 <filename> 例子:  git blame -L 38,38 src/component/BarCode/i ...

  6. (转)一篇写的简明易懂的logging模块

    转:http://kenby.iteye.com/blog/1162698 一.从一个使用场景开始 开发一个日志系统, 既要把日志输出到控制台, 还要写入日志文件 import logging # 创 ...

  7. 谈谈javascript中的变量提升还有函数提升

    在很多面试题中,经常会看到关于变量提升,还有函数提升的题目,所以我就写一篇自己理解之后的随笔,方便之后的查阅和复习. 首先举个例子 foo();//undefined function foo(){ ...

  8. 王者荣耀交流协会final冲刺第五次scrum会议

    成员王超,高远博,冉华,王磊,王玉玲,任思佳,袁玥全部到齐,王磊拍照. master:高远博 2.时间跨度 2017年12月5日 18:00 - 18:31,总计31分钟 3.地点 一食堂二楼沙发座椅 ...

  9. HDU 5170 GTY's math problem 水题

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5170 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  10. 整理sql server数据类型

    我们在平常开发过程中,在设计数据的时候,经常碰到数据类型选择的问题,为了更快,更合适地选择正确的数据类型,所以在这里做个总结. 分类 sql server 数据类型 c# 数据类型 描述 应用场景 字 ...