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. HADOOP操作权限问题

    hdfs的权限判断十分简单,就是拿发出指令的user name和文件的user name 做比较   private void check(INode inode, FsAction access   ...

  2. hive的简单使用

    一.一些说明 1.支持的操作 hive 默认不支持updata 和 delete操作 insert也是执行缓慢,主要用于数据的计算 hive 数据类型---字符串,大部分与java一致. 2.内外表的 ...

  3. 套接口socket编程(Client/Server编程实例)

    基本概念 套接口也就是网络中的ID.网络通信,归根到底还是进程间通信(不同计算机上的进程间的通信).在网络中,每一个节点(计算机或路由器)都有一个网络地址,也就是IP地址. IP地址:在网络中唯一标识 ...

  4. 简单在kubernetes中安装cadvisor

    cadvisor用于分析docker资源占用情况及性能的工具 安装命令: docker run --volume=/:/rootfs:ro --volume=/: --detach=true --na ...

  5. springboot集成jpa,在postgresql数据库中创建主键自增表

    依赖文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http:/ ...

  6. NodeJS实现同步的方法

    NodeJS被打上了单线程.非阻塞.事件驱动…..等标签. 在单线程的情况下,是无法开启子线程的.经过了很久的研究,发现并没有thread函数!!!但是有时候,我们确实需要“多线程”处理事务.node ...

  7. 记录一次爬虫报错:Message: Failed to decode response from marionette

    由于标题中的错误引发: Message: Tried to run command without establishing a connection 解释: 先说一下我的爬虫架构,用的是firefo ...

  8. 微软职位内部推荐-Principal Development Lead - SharePoint

    微软近期Open的职位: SharePoint is a multi-billion dollar enterprise business that has grown from an on-prem ...

  9. Facebook190亿美元收购WhatsApp

    Facebook收购WhatsApp,前后只花费10天时间.这是Facebook迄今规模最大的一笔收购,可能也是史上最昂贵的一笔针对靠私人风投起家的企业的收购案. 2月9日,马克•扎克伯格(Mark ...

  10. mysqldb下载地址

    mysqldb x64    https://pan.baidu.com/s/1dFJ3G0T x32及源码 https://pypi.python.org/pypi/MySQL-python/1.2 ...