我试图在浏览器中显示PDF - 如果可能的话 - 我知道我可以在Chrome中执行此操作,这是我正在测试的.问题是,每次我尝试时,它都会提示下载.
我正在使用PHP会话,所以我知道有一些无关的标题被发送,所以我打电话header_remove()来重置所有内容.
我将此函数称为显示PDF:
<?php
// For demonstrative purposes
session_start();
if (!isset($_SESSION['auth'])) {
header('Location: login.php');
die;
}
/*
* void viewPDF (Report $report)
* Outputs the PDF of the report
*/
function viewPDF ($report) {
// Tell the browser we are going to serve a PDF file.
$file = dirname(__FILE__).'/../reports/'.$report->id.'.pdf';
// The location of the PDF
if (!file_exists($file)) {
die ('The PDF does not exist.');
// Somehow the file does not exist.
}
header_remove();
// …Run Code Online (Sandbox Code Playgroud) 鉴于以下内容:
[HttpGet]
[ActionName("GetContent")]
public HttpResponseMessage GetContent(int id)
{
Content content = _uow.Contents.GetById(id);
if (content == null)
{
var message = string.Format("Content with id = {0} not found", id);
return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
}
else
{
return Request.CreateResponse(HttpStatusCode.OK, content);
}
}
Run Code Online (Sandbox Code Playgroud)
和:
[HttpGet]
[ActionName("GetContent")]
public HttpResponseMessage GetContent(int id)
{
try
{
Content content = _uow.Contents.GetById(id);
if (content == null)
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
return Request.CreateResponse<Content>(HttpStatusCode.OK, content);
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
Run Code Online (Sandbox Code Playgroud)
我见过两种编码风格.一个使用例外,另一个不使用.一个使用CreateResponse <>和另一个CreateResponse().有人能说出使用这些有什么优点/缺点吗?据我所知,第二种方法似乎看起来更完整但是真的需要使用try/catch来做这么简单的事情吗?
我一直在使用delphi的应用程序,其中应用程序需要连接像"example.example.ex"这样的URL.
当我调用该函数IdHTTP1.Post时,日期enconding过程中发生错误.
发生的情况是,当应用程序获得某些连接头的值时,"Expires"为-1,而function RawStrInternetToDateTime(var Value: string): TDateTime;内部使用的函数EncodeDate(Year, Month, Day);不能使用值"-1".
我是否需要直接将"exemple.exemple.ex","expires"值更改为其他某个日期时间值?
在我的angularjs应用程序中,我正在与后端服务器通信,后端服务器需要通过http头进行基本访问身份验证.我已经描述实现对客户端的认证机制在这里.
angular.module('myAuthModule')
.config(['$httpProvider', '$stateProvider',
function ($httpProvider, $stateProvider) {
$httpProvider.interceptors.push('securityInterceptor');
}])
.factory('securityInterceptor', ['$location', '$window', '$q',
function ($location, $window, $q) {
return {
request: function (config) {
config.headers = config.headers || {};
if ($window.sessionStorage.token) {
config.headers['Auth-Key'] = $window.sessionStorage.token;
}
return config;
},
response: function (response) {
if (response.status === 401 || response.status === 403) {
$location.path('/login');
}
return response || $q.when(response);
}
};
}
]);
Run Code Online (Sandbox Code Playgroud)
到目前为止一切顺利,在角度应用程序中处理xhr请求按预期工作.
问题是我需要提供pdf文档的下载链接.我的后端服务器有一个/Document/Pdf/:id资源,用于application/pdf响应ContentDisposition: attachment,还需要进行身份验证.我知道我无法使用xhr启动下载,但是它们都提供了文档下载链接,ngHref并调用了一个功能,例如$window.open('/Document/Pdf/13')导致401 Unauthorized …
鉴于以下System.Net.Http.HttpClient Portable Class Library引发异常:
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Authorization", "aaaa,bbbb");
Run Code Online (Sandbox Code Playgroud)
例外情况是:格式无效
在
1 values, System.Net.Http.Headers.HeaderInfo headerInfo, Boolean ignoreInvalid) [0x0004c] in /Developer/MonoTouch/Source/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaders.cs:195 at System.Net.Http.Headers.HttpHeaders.Add (System.String name, IEnumerable/Developer/MonoTouch/Source/mono/mcs/class/System.Net.Http/System.Net.Http 中的System.Net.Http.Headers.HttpHeaders.AddInternal(System.String name,IEnumerable 1 values)[0x00011] .Headers/HttpHeaders.cs:170位于/ Developer/MonoTouch/Source/mono/mcs/class/System中的System.Net.Http.Headers.HttpHeaders.Add(System.String name,System.String value)[0x00000]. Net.Http/System.Net.Http.Headers/HttpHeaders <... snip ...>
现在这只发生在以下情况
标题键= Authorization.如果你把它改成其他任何东西,那没关系.值=必须有逗号.
现在,这个先前的SO问题表明逗号是在标题中粘贴多个值的正确方法.
谁能解释一下发生了什么?
注意:这是在Xamarin上,所以我猜它是单声道的.不确定这是否重要.
更新:
这是一张照片.

Clients SHOULD NOT include a Referer header field in a (non-secure) HTTP request if the referring page was transferred with a secure protocol.
https://tools.ietf.org/html/rfc2616#section-15.1.3
根据该标准,https://google.com不应将引荐发送到非安全网站,但确实如此.其他HTTPS站点是否将引荐发送到HTTP站点?
所有这些测试都是使用Chrome v33.0.1750.117完成的
要运行测试,我转到第一页,然后打开控制台并手动执行重定向. location = "http://reddit.com";
防爆.
https://google.com - > http://www.reddit.com 保留推荐
https://startpage.com/ - > http://www.reddit.com推荐被剥夺
https://bankofamerica.com - > http://reddit.com推荐被剥夺
https://facebook.com - > http://reddit.com推荐被剥夺
谷歌是否做了一些特别的事情来保持推荐?是否有保留推荐的HTTPS站点列表?是否还有其他情况需要删除推荐?
谢谢!
是否可以使用GZIP内容编码获取您网站内容的全部或大部分并通过单个响应发送给客户端?例如,压缩一个响应中的图像,HTML,CSS和JS文件.浏览器是否能够提取内容并将其组合在一起以显示页面?
我的理解是它只能用一个文件完成,并从HTML,CSS和JavaScript文件中获得最大的好处.到目前为止,我已经在网上搜索了几个小时,一无所获.
当然,我知道有些框架会将您的文件捆绑成一个,然后您可以在服务器上启用压缩并使用GZIP内容编码发送它.但我相信你只能把像四个CSS文件这样的文件捆绑成一个CSS文件,将六个JS文件捆绑到一个JS文件中等等.
我之前没有看到这个问题得到解答,因此我们将非常感谢任何见解.
我有一个rails应用程序,为注册用户提供大型静态文件.我可以按照这里的优秀指南来实现它:使用nginx,Rails 3.0和#send_file进行受保护的下载.下载和其他一切工作都很好,但只有这个问题 - Content-Length标题没有被发送.

对于小文件是可以的,但是当下载大文件时它会非常令人沮丧,因为下载管理器和浏览器没有显示任何进展.我怎样才能解决这个问题?我是否必须在nginx配置中添加一些内容,或者是否必须将其他选项传递给send_file我的rails控制器中的方法?我一直在网上搜索相当一段时间,但都没有成功.请帮忙!谢谢!
这是我的nginx.conf:
upstream unicorn {
server unix:/tmp/unicorn.awesomeapp.sock fail_timeout=0;
}
server {
listen 80 default_server deferred;
# server_name example.com;
root /home/deploy/apps/awesomeapp/current/public;
location ~ /downloads/(.*) {
internal;
alias /home/deploy/uploads/$1;
}
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Sendfile-Type X-Accel-Redirect;
proxy_set_header X-Accel-Mapping /downloads/=/home/deploy/uploads/;
proxy_pass http://unicorn;
}
error_page 500 502 …Run Code Online (Sandbox Code Playgroud) 所以目前我正在使用以下代码从URL中检索数据
Document doc = Jsoup.connect(url).get();
Run Code Online (Sandbox Code Playgroud)
在我获取数据之前,我已经决定要获取内容类型,所以我使用以下内容来实现.
Connection.Response res = Jsoup.connect(url).timeout(10*1000).execute();
String contentType = res.contentType();
Run Code Online (Sandbox Code Playgroud)
现在我想知道,这是两个独立的连接吗?这不高效吗?有没有办法让我在一个连接中获取内容类型和文档数据?
谢谢
为了节省服务器资源,我正在寻找一种使用javascript检索给定网址的内容类型的方法.它不应该只从标题的URL下载完整的内容.这有可能与javascript有限制.
http-headers ×10
javascript ×3
c# ×2
http ×2
.net ×1
ajax ×1
angularjs ×1
asp.net-mvc ×1
caching ×1
content-type ×1
delphi ×1
indy ×1
java ×1
jsoup ×1
nginx ×1
pdf ×1
php ×1
referrals ×1
rest ×1