标签: http-headers

为什么我的 ETag 标头在 IIS 下有效,而在 VS2010 Web 服务器下无效?

在我的 ASP.NET MVC 2 应用程序中,我有以下几行:

Response.Cache.SetMaxAge(TimeSpan.FromDays(90));
Response.Cache.SetETag(lastWriteTime.Value.Ticks.ToString());
Run Code Online (Sandbox Code Playgroud)

使用 Fiddler 跟踪 HTTP 流,我可以看到:

ETag: 634473035667000000
Run Code Online (Sandbox Code Playgroud)

在 IIS7 下运行时,在响应标头中,但是当我在 Visual Studio 2010 Web 服务器下运行时,这个标头只是......消失了。无论我是通过 Response.Cache.SetETag() 还是通过 Response.AppendHeader("ETag", etag) 设置它,它都不会返回。

这是 IIS Web 服务器的“功能”吗?是否有一些我错过的配置设置?如果我必须附加到 IIS 进程才能调试任何东西,这将使测试缓存失效有点繁琐......

编辑:看起来,尽管调用了 Response.Cache.SetCacheability(HttpCacheability.Public),VS/Cassini 总是返回 HTTP Cache-Control 设置为“私有”的资源......这有帮助吗?

asp.net-mvc etag cassini webdev.webserver http-headers

0
推荐指数
1
解决办法
2350
查看次数

在 Safari 中强制下载文件

我正在尝试使文件可在 Safari 中下载。这是我的代码:

<?php
$file = $_GET['file'];
header ("Content-Disposition: attachment");
header ("Content-type: application/octet-stream");
header ("Content-disposition: attachment; filename=".$file.";");
header("Content-Length: ".filesize($file));
readfile($file);
exit;
?>
Run Code Online (Sandbox Code Playgroud)

它在 FF 中工作正常,但在 Safari 中我得到一个 0kb 文件。

我想我发送的标题有问题。可能是什么错误?

php safari file http-headers

0
推荐指数
1
解决办法
9699
查看次数

如何访问select2中的HTTP响应头

我正在使用select2来构建带有延迟附加结果列表的选择框。但是,分页数据(例如总项目数)不是 JSON 响应的一部分。因此,我无法在ajax.results函数中访问它们。相反,分页数据是 HTTP 响应标头的一部分。

select2的ajax中是否内置了某种拦截机制,以便我可以访问HTTP标头并将它们写入实际结果数据中?

ajax jquery http-headers jquery-select2

0
推荐指数
1
解决办法
1102
查看次数

如何获取 xmlhttp 请求的 URL (AJAX)

w3schools.com (url) 上有一个示例,说明如何使用纯 Javascript 进行 AJAX 调用。如果您查看示例,您将看到调用是由按钮触发的:

<button type="button" onclick="loadXMLDoc()">Change Content</button>
Run Code Online (Sandbox Code Playgroud)

这是函数:

function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
Run Code Online (Sandbox Code Playgroud)

我想要做的是获取传出 AJAX 调用的 URL,即ajax_info.txt (url):

xmlhttp.open("GET","ajax_info.txt",true);
Run Code Online (Sandbox Code Playgroud)

我试图将该 URL 放入警报中,所以我尝试调用响应的标头,getAllResponseHeaders()希望它会给我Host这样的:

if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    alert(xmlhttp.getAllResponseHeaders());
Run Code Online (Sandbox Code Playgroud)

它确实给了我所有的标题,但没有给我主机。所以我的下一步是尝试自己设置主机,setRequestHeader()但后来我意识到标题需要一个我必须自己发送的值,所以这行不通。我还能尝试获取/获取警报中的传出 AJAX URL 吗? …

javascript ajax jquery get http-headers

0
推荐指数
1
解决办法
3355
查看次数

PHP:获取 fopen() HTTP 响应错误代码

我想在通过fopen()函数打开远程文件时获取 HTTP 错误代码。

我有以下代码:

$remote = fopen ($url, "rb");
Run Code Online (Sandbox Code Playgroud)

如果 URL 正确,文件将被打开。否则,fopen会触发类似于 的错误消息Warning: fopen(url): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

我知道@在 之前添加fopen()抑制错误消息
但是我怎样才能获得 http 错误代码呢?

在这里,我想进入HTTP/1.1 404 Not Found一个变量。

谢谢。

php fopen http-headers

0
推荐指数
1
解决办法
6666
查看次数

无需加载即可播放 HTML5 视频

我有一个问题,当我用 HTML5 播放器播放一个大文件时,它会在 5 分钟后开始播放,因为他在播放前先下载了视频。无论视频大小如何,如何立即开始播放并让它在播放时下载?

在谷歌上搜索了 3 天,但没有找到任何东西。我希望有人可以帮助我,谢谢

HTTP 标头(不是文件路径)

Status: HTTP/1.1 200 OK
Server: nginx   
Date:   Fri, 19 Sep 2014 15:38:02 GMT   
Content-Type:   text/html; charset=UTF-8    
Transfer-Encoding:  chunked 
Connection: close   
X-Powered-By:   PHP/5.4.32  
Cache-Control:  no-store, no-cache, must-revalidate, max-age=0  
Cache-Control:  post-check=0, pre-check=0   
Pragma: no-cache    
Content-Encoding:   gzip
Run Code Online (Sandbox Code Playgroud)

HTTP 标头(文件路径)

GET patt/to/file HTTP/1.1[CRLF]
Host: domain[CRLF]
Connection: close[CRLF]
User-Agent: Web-sniffer/1.1.0 (+http://web-sniffer.net/)[CRLF]
Accept-Encoding: gzip[CRLF]
Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7[CRLF]
Cache-Control: no-cache[CRLF]
Accept-Language: de,en;q=0.7,en-us;q=0.3[CRLF]
Referer: http://web-sniffer.net/[CRLF]
Run Code Online (Sandbox Code Playgroud)

需要让它在第一个上工作

html video mp4 http-headers

0
推荐指数
1
解决办法
1910
查看次数

如何禁用特定 Wordpress url 上的 404 标头

我使用此代码将特定 url 重定向到我定制的 Wordpress 主题上的 php 文件:

add_action('wp', function() {
if ( trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/') === 'pagename' ) {
include(locate_template('mysciprt.php'));
exit();
}});
Run Code Online (Sandbox Code Playgroud)

(我知道我可以使用重写规则,但出于一些原因我需要使用此代码)。

它的工作很棒。问题是该页面仍然有一个 404 状态的 http 标头。这是一个问题,原因有几个(其中一些是:seo,不能使用发布脚本......)。

我的问题是:有什么办法可以解决吗?

我尝试过的:

我尝试添加:

global $wp_query;
status_header(200);
$wp_query->is_page = true;
$wp_query->is_404  = false;
Run Code Online (Sandbox Code Playgroud)

一开始没有帮助,然后我改变了我action('wp'..action('init'...,它起作用了!但问题是我使用'wp'而不是'init'因为我需要get_query_var()在这个脚本上使用而我不能在使用'init'动作时使用。

php wordpress url-rewriting http-headers http-status-code-404

0
推荐指数
1
解决办法
1648
查看次数

如何在 HTTP 标头值中放置回车符

我有一个类似于以下内容的 HTTP Web 请求:

    Dim myrequest As HttpWebRequest = HttpWebRequest.Create("myURL")
    myrequest.Proxy = Nothing
    myrequest.UserAgent = "AGENT"
    myrequest.Method = "POST"
    myrequest.ContentLength = 0

    myrequest.Headers.Add("KEY1", value)
    myrequest.Headers.Add("KEY2", value)


    Dim myresponse As HttpWebResponse = myrequest.GetResponse
    Dim mystream As System.IO.Stream = (myresponse.GetResponseStream)

    Dim streamreader As New System.IO.StreamReader(mystream)
    return streamreader.ReadToEnd
Run Code Online (Sandbox Code Playgroud)

问题是我无法发送以下任何值来在标题值中放置换行符。到目前为止,我已经尝试过:

新行

vbCrLf

vbCR

低频

这些会产生一个错误,指出“指定的值具有无效的 CRLF 字符”我也试过

\n

\r\n

它只是将字符串文字添加到我的值中,不包括回车符。在服务器端,我想获取此标题中包含的值并将其放入 MySQL 的列中。

vb.net http http-headers

0
推荐指数
1
解决办法
1946
查看次数

在不知道扩展名的情况下使用 python 下载文件。- 内容类型 - 流

嘿,我刚刚做了一些研究,发现我可以从以filename.extension结尾的 url 下载图像,例如000000.jpeg。我现在想知道如何下载没有任何扩展名的图片。这是我想下载图片的网址 http://books.google.com/books/content?id=i2xKGwAACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api 当我将网址直接放入浏览器时,它会显示一张图片

此外,这是我尝试过的:

from six.moves import urllib

thumbnail='http://books.google.com/books/content?id=i2xKGwAACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api'

img=urllib.request.Request(thumbnail)
pic=urllib.request.urlopen(img)
pic=urllib.request.urlopen(img).read()
Run Code Online (Sandbox Code Playgroud)

Anyhelp将不胜感激

python stream http-headers python-3.x python-requests

0
推荐指数
1
解决办法
1583
查看次数

@EnableWebMvc annotation changes response encoding

By default, my Spring Boot application responds to any request with the following Content-Type headers:

Content-Type: text/html;charset=UTF-8
Run Code Online (Sandbox Code Playgroud)

I believe this has been so from the beginning and I would like to keep it this way.

However, by making a simple change and only adding @EnableWebMvc to my @SpringBootApplication annotated class, the charset attribute is changed:

Content-Type: text/html;charset=ISO-8859-1
Run Code Online (Sandbox Code Playgroud)

And so the UTF-8 encoded content of the response is displayed incorrectly on the website.

spring spring-mvc character-encoding http-headers spring-boot

0
推荐指数
1
解决办法
64
查看次数