Tag: http headers

服务gzip文件时使用什么'Content-Type'标题?

我正在提供我的CSS / JavaScript文件的gzipped副本。 根据教程,我在提供这些文件时将内容types设置为application/gzip 。 但是,铬似乎并没有解压这些文件,而对于JavaScript文件,我收到了很多“非法字符”的错误。 如果我查看源代码,我仍然看到文件被压缩,而不是未压缩。 我的问题是,我应该为这些文件设置什么内容types,以便浏览器将它们正确解释为gzip的css / js文件,然后解压缩它们? 如果我只是设置text/javascript或text/css ,浏览器仍解释他们正确? 编辑:完整的回复标题: HTTP/1.1 200 OK x-amz-id-2: UIBkZT/MuFxsmn+3nVOzEO63rRY99l3traCbMExUgSdGHUrOIPtNp34h1+ujYKmt x-amz-request-id: 19346C9B01D8FC62 Date: Mon, 12 May 2014 03:59:51 GMT Content-Encoding: gzip Last-Modified: Mon, 12 May 2014 02:24:54 GMT ETag: "561080b5e19f6daea2e74fd5a0623c79" Accept-Ranges: bytes Content-Type: application/x-gzip Content-Length: 5153 Server: AmazonS3

通过套接字手动发送HTTP请求

当我通过一个套接字发送一个正常的HTTP请求时,服务器不响应一个OK响应。 我从FireFox复制HTTP头。 这里是代码: Socket s = new Socket(InetAddress.getByName("stackoverflow.com"), 80); PrintWriter pw = new PrintWriter(s.getOutputStream()); pw.print("GET / HTTP/1.1"); pw.print("Host: stackoverflow.com"); pw.flush(); BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); String t; while((t = br.readLine()) != null) System.out.println(t); br.close(); 不过,这是我收到的答复: HTTP/1.0 408 Request Time-out Cache-Control: no-cache Connection: close Content-Type: text/html <html><body><h1>408 Request Time-out</h1> Your browser didn't send a complete […]

如何在使用formdata时在XMLHttpRequest中添加标题数据?

我试图实现一个file uploadAPI,在这里给出: Mediafirefile upload 我成功地能够上载Post数据和获取数据 ,但是不知道如何发送x-filename属性,这个属性是API指南中给出的Header数据 。 我的代码: xmlhttp=new XMLHttpRequest(); var formData = new FormData(); formData.append("Filedata", document.getElementById("myFile").files[0]); var photoId = getCookie("user"); // formData.append("x-filename", photoId); //tried this but doesn't work // xmlhttp.setRequestHeader("x-filename", photoId); //tried this too (gives error) [edited after diodeous' answer] xmlhttp.onreadystatechange=function() { alert("xhr status : "+xmlhttp.readyState); } var url = "http://www.mediafire.com/api/upload/upload.php?"+"session_token="+getCookie("mSession")+"&action_on_duplicate=keep"; xmlhttp.open("POST", url); // […]

如何在ExpressJS中删除X-Powered-By

我想删除X-Powered-By for Security,在ExpressJS(node.js)中保存带宽。 怎么做? 它可能是filter(app.use)? app.use(function(req,res,next_cb){ /* remove X-Powered-By header */ next_cb(); }

不同的是:accept-encoding是什么意思?

谷歌的网页速度插件告诉我: The following publicly cacheable, compressible resources should have a "Vary: Accept-Encoding" header: //some .js and .css files 我不明白这是什么意思。 我已经压缩这些文件,如下所示: if (encodings.Contains("gzip") || encodings == "*") { app.Response.Filter = new GZipStream(baseStream, CompressionMode.Compress); app.Response.AppendHeader("Content-Encoding", "gzip"); } 而这一切似乎工作。 为什么有Vary: Accept-Encoding必须Vary: Accept-Encoding ?

X-Forwarded-Host头文件的真实用法?

我在X-Forwarded-*头文件中发现了一些有趣的内容,包括Apache文档中的反向代理请求头部分,以及X-Forwarded-For的维基百科文章 。 我明白那个: X-Forwarded-For给出了连接到代理的客户端的地址 X-Forwarded-Port给客户端连接的端口(例如80或443 ) X-Forwarded-Proto给出用于连接到代理的客户端协议( http或https ) X-Forwarded-Host给出客户端发送给代理的Host头的内容。 这些都是有道理的。 但是,我仍然无法弄清楚X-Forwarded-Host的真实生活用例。 我知道需要在不同的端口上重复连接,或者使用不同的scheme,但为什么代理服务器在向目标服务器重复请求时会更改Host头?

强制nginx发送特定的Content-Type

如何覆盖nginx默认的内容types? 目前当我请求01.dae文件的时候, Content-Type: application/octet-stream; 我想要它 Content-Type: application/xml; 我试过类似的东西 location ~* \.dae$ { types { }; default_type application/xml; } 和 location ~* \.dae$ { add_header Content-Type application/xml; } 但没有任何工作。

AngularJS中的$ http Auth头文件

我有一个angular色应用程序正在击中节点API。 我们的后端开发者已经在API上实现了基本的身份validation,我需要在我的请求中发送一个auth头文件。 我已经查明: $http.defaults.headers.common['Authorization'] = 'Basic ' + login + ':' + password); 我试过了: .config(['$http', function($http) { $http.defaults.headers.common['Authorization'] = 'Basic ' + login + ':' + password); }]) 以及直接附加到请求: $http({method: 'GET', url: url, headers: {'Authorization': 'Basic auth'}})}) 但没有任何工作。 如何解决这个问题?

使IE来caching资源,但总是重新validation

caching控制头“no-cache,must-revalidate,private”允许浏览器caching资源,但强制使用条件请求进行重新validation。 这在FF,Safari和Chrome中按预期工作。 但是,IE7 + 8不发送条件请求,即请求头中缺less“If-Modified-Since”,因此服务器使用HTTP / 200而不是HTTP / 304进行响应。 以下是完整的服务器响应头文件: Last-Modified: Wed, 16 Feb 2011 13:52:26 GMT Content-type: text/html;charset=utf-8 Content-Length: 10835 Date: Wed, 16 Feb 2011 13:52:26 GMT Connection: keep-alive Cache-Control: no-cache, must-revalidate, private 这看起来像一个IE错误,但我没有发现任何相关的networking上,所以我想知道是否缺席或存在的另一个头使IE的行为奇怪? 关于no-cache和max-age之间差别的一个很好的讨论: Cache-Control:max-age = 0和no-cache之间有什么区别?

自定义标题为Httpclient请求

如何将自定义标头添加到HttpClient请求。 我正在使用PostAsJsonAsync方法发布json。 我需要添加的自定义标题是 "X-Version: 1" 这是我迄今为止所做的: using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://api.clickatell.com/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "xxxxxxxxxxxxxxxxxxxx"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = client.PostAsJsonAsync("rest/message", svm).Result; }