pdf 下载整理
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 下载整理的更多相关文章
- MySQL管理之道,性能调优,高可用与监控(第二版)pdf下载
MySQL管理之道,性能调优,高可用与监控(第二版) 书中内容以实战为导向,所有内容均来自于笔者多年实践经验的总结和新知识的拓展,同时也针对运维人员.DBA等相关工作者会遇到的有代表性的疑难问题给出了 ...
- 手机user agent大全下载 整理发布一批移动设备的user agent【分享】
手机user agent大全下载 整理发布一批移动设备的user agent[分享] 很多人朋友在玩浏览器的时候 或者写软件的时候需要用到 user agent 这个东西 修改这个 可以使自己的浏览器 ...
- Spring Boot 系列教程18-itext导出pdf下载
Java操作pdf框架 iText是一个能够快速产生PDF文件的java类库.iText的java类对于那些要产生包含文本,表格,图形的只读文档是很有用的.它的类库尤其与java Servlet有很好 ...
- 肖秀荣8套卷2018pdf下载|2018肖秀荣冲刺8套卷pdf下载电子版
肖秀荣8套卷2018pdf下载|2018肖秀荣冲刺8套卷pdf下载电子版 下载链接: https://u253469.ctfile.com/fs/253469-229815828
- pdf 下载demo
最近写了个pdf下载的demo,在这里记录一下.. 1 要下载pdf首先要有pdf 模板 ,制作pdf 模板就是 word 另存为 pdf . 2 用 Adobe Acrobat X Pro 这个软 ...
- [原]Jenkins(一)---我理解的jenkins是这样的(附全套PDF下载)
/** * lihaibo * 文章内容都是根据自己工作情况实践得出. *版权声明:本博客欢迎转发,但请保留原作者信息! http://www.cnblogs.com/horizonli/p/5330 ...
- 蘑菇街支付架构 PDF 下载
蘑菇街支付架构 PDF 下载 下载地址:链接:https://pan.baidu.com/s/1ZffetaUhVMOzb9j2PSQJIQ 密码:iays http://www.java1234.c ...
- swift user guide.pdf下载
日志以便日后查找.谢谢 1 Swift User Guide.pdf下载 http://download.csdn.net/detail/swifttrain/7442921 2 The Swift ...
- 码书:编码与解码的战争 PDF 下载
码书:编码与解码的战争 PDF 下载 下载地址:https://pan.baidu.com/s/14Y_krHh-unOv4g2KYFFDgQ 如需分享码:[打开微信]->[扫描右侧二维码]-& ...
随机推荐
- nginx启动、停止重启
启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /us ...
- Golang项目开发管理
工具 1. task(项目管理,类似于make) go get -u -v github.com/go-task/task/cmd/task 2. gopm(go依赖管理) go get -u git ...
- eclipse安装反编译器jad
1.下载net.sf.jadclipse_3.3.0.jar.jadclipse_3.3.0.jar.jad.exe 2.将net.sf.jadclipse_3.3.0.jar放在eclipse的安装 ...
- Alpha发布_文案+美工
团队名称:探路者 1蔺依铭:http://www.cnblogs.com/linym762/ 2张恩聚:http://www.cnblogs.com/zej87/ 3米赫:http://www.cnb ...
- 第18次Scrum会议(10/30)【欢迎来怼】
一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华 小组照片 二.开会信息 时间:2017/10/30 17:19~17:38,总计19min.地点:东北师 ...
- "firstday"-软件工程
阅读以下文章 http://www.thea.cn/news/terminal/9/9389.html http://www.shzhidao.cn/system/2015/09/22/0102 ...
- 3dContactPointAnnotationTool开发日志(三一)
在玩的时候遇到了一个python的问题: Traceback (most recent call last): File ".\convert.py", line 13, in ...
- opencv 矩阵类数据的运算
参考:http://blog.sina.com.cn/s/blog_7908e1290101i97z.htmlhttp://blog.sina.com.cn/s/blog_afe2af380101bq ...
- 【bzoj3064】Tyvj 1518 CPU监控 线段树维护历史最值
题目描述 给你一个序列,支持4种操作:1.查询区间最大值:2.查询区间历史最大值:3.区间加:4.区间赋值. 输入 第一行一个正整数T,表示Bob需要监视CPU的总时间. 然后第二行给出T个数表示在你 ...
- Git Gerrit Repo User Manual
Git Repo Gerrit User Manual Revision History Revision # Description Date Author ...