我正在编写一个 Web 应用程序框架。为了正确支持反向代理服务器,我想确保每当 Web 应用程序访问 cookie 数据时,发送给用户的页面只会为该用户缓存。据我所知,有两种方法可以实现这一点:
header('Vary: Cookie');
Run Code Online (Sandbox Code Playgroud)
或者
header('Cache-Control: private');
Run Code Online (Sandbox Code Playgroud)
使用的直接好处Vary: Cookie是反向代理服务器将缓存未经身份验证的请求。但是,我们正在使用通过 javascript 创建 cookie 的 Google Analytics - 所以我担心 Vary: Cookie 方法不可用?
刚开始使用 Node.js,在看到几个例子后,我发现通常Content-Type在返回一些内容之前设置。
对于 HTML,通常是这样的:
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(html);
res.end();
Run Code Online (Sandbox Code Playgroud)
对于图像:
res.writeHead(200, {'Content-Type': 'image/png'});
res.write(img, 'binary');
res.end();
Run Code Online (Sandbox Code Playgroud)
我阅读了.write()的文档,它说如果没有指定标题“它将切换到隐式标题模式并刷新隐式标题”
通过一些测试,我发现我可以像这样写一行:
res.end(html); // or
res.end(img);
Run Code Online (Sandbox Code Playgroud)
这两个工作正常。我还使用本地 Apache 服务器进行了测试,当我查看加载图像时设置的标头时,那里没有Content-Type设置标头。
我需要麻烦设置它们吗?如果我不这样做,可能会出现什么情况或错误?
我正在开发一个针对 Android 和 iOS 平台的跨平台应用程序。我使用 jQuery 1.9.1、Jquery Mobile 1.3.1 和 Phonegap 2.8.0。
我想发送一个ajax请求并设置请求头“Connection”和“Keep-Alive”。在操作系统高于 4.1(其默认浏览器是 Chrome)的 Android 手机上,我收到一条错误消息,显示“拒绝设置不安全的标题“连接””。
我可以在低端设备甚至 iPhone 上发送此类请求。
任何人都可以请帮助我。
我必须在请求中设置这 2 个标头。
提前致谢。
我需要从 javascript websocket 连接访问响应头。有没有办法访问这些响应头?或者至少是响应代码?
我只能访问 onclose、onerror、onopen 事件以及一些(不可用 - 对我而言)属性!
我们正在使用自托管的 WebApi,我们需要删除所发送响应的服务器标头(服务器:Microsoft-HTTPAPI/2.0)。
由于它是自托管的,因此 HttpModule 不是一种选择。实现 a DelegatingHandler,访问标头以及添加是可能的。在asp.net网站很好的细节,如何能够做到这一点。
但是服务器标头似乎是在管道中稍后添加的,因为它没有在HttpResponseMessage我们从DelegatingHandler. 但是,我们可以添加值。
async protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
response.Headers.Server.Add(new ProductInfoHeaderValue("TestProduct", "1.0"));
response.Headers.Add("Server", "TestServerHeader");
return response;
}
Run Code Online (Sandbox Code Playgroud)
双方Server.Add并.Add正常工作。response.Headers.Remove("Server");但是不起作用,因为服务器标头未设置,response.Headers.Server为空。
有什么我想念的吗?
所以我的一些 PHP 文件中有这些标题:
<?php
header('Content-Type: text/html; charset=UTF-8');
header('Content-Style-Type: text/css');
header('Content-Script-Type: application/javascript');
header('HTTP/1.1 200 OK');
header('Content-language: en-US');
header('X-Powered-By: PHP/5.2.17');
header('Last-Modified: Tue, 01 Jan 2013 00:00:00 GMT');
header('Cache-Control: no-store, no-cache, max-age=0, must-revalidate');
header('Pragma: no-store, no-cache, max-age=0, must-revalidate');
header('Expires: Tue, 01 Jan 2013 00:00:00 GMT');
?>
Run Code Online (Sandbox Code Playgroud)
如何在我的 .htaccess 文件中设置它们?(应该仅适用于特定文件),这是我到目前为止所得到的:
<FilesMatch "^(index.php|about.php|contact.php)$">
# HTTP Headers should be set in here
</FilesMatch>
Run Code Online (Sandbox Code Playgroud) 所以我有一个通过 Android WebView 运行的 web 应用程序,我需要document.referrer在我的网页上的 JavaScript 中正确使用。我尝试了以下方法:
webView.setWebViewClient(new MyWebViewClient());
private class MyWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Referer", view.getUrl());
view.loadUrl(url, headers);
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
但它似乎没有正确通过。我在里面设置了一个断点,检查了 headers 变量,url 是正确的,但是document.referrer从下一页的 JavaScript 调用的值与我设置的不匹配。
我为之前在 SO 上问过一万次的问题而道歉。这种情况似乎与其他情况不同。简而言之,通过 Firefox 和 Chrome 播放视频总是有效,但在 Internet Explorer、所有版本、所有 Windows 版本中总是失败。
我有一个根据 Microsoft 的 HTML5 建议设置的网页。模态窗口提供视频:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
</head>
<body>
<div class="popupwindow">
<video controls autoplay preload="auto" style="width:100%">
<source src="streamvideo.rails?file=$fileName" type="video/mp4" />
</video>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
streamvideo.rails 是 Castle Monorail C# 函数,它获取云服务器中的视频文件作为 Stream 并将其作为范围请求流式传输回来。
首先,我确定这不是常见的问题:编解码器可能没问题,响应的 Content-Type 是正确的(视频/mp4)并且 IE 甚至正确地接收视频,至少最初是这样。浏览器内的网络嗅探器显示它收到了一小块 MP4 文件,然后停止了。
我注意到一个奇怪的地方:IE 没有将视频请求作为范围请求,而 Chrome/FF 是。Chrome 的标题:
GET [my URL]?fileName=e65b0b0d-0911-4e3f-bc71-7b5d5a65db57.mp4 HTTP/1.1
Host: localhost
Connection: keep-alive
Accept-Encoding: identity;q=1, *;q=0
User-Agent: Mozilla/5.0 …Run Code Online (Sandbox Code Playgroud) 什么是正确/首选的 REST api 设计来获取取决于时区的数据?
我正在考虑简单地将时区添加为 URL 参数,因此:
$ curl www.api.example.com/data?timezone="Europe/Amsterdam"
Run Code Online (Sandbox Code Playgroud)
但是有人建议以类似于 github 的方式使用自定义标头:
$ curl -H "X-Time-Zone: Europe/Amsterdam" www.api.example.com/data
Run Code Online (Sandbox Code Playgroud)
https://developer.github.com/v3/#using-the-time-zone-header
我想知道在这里使用 header 而不是 param 有什么好处?这样的决定背后是否有任何设计模式?
在 WCF (System.Net.WebHeaderCollection) 中,可以使用 System.Net.HttpRequestHeader 枚举或标头字符串检索标头值:
WebOperationContext.Current.IncomingRequest.Headers[httpRequestHeaderEnum]
// or
WebOperationContext.Current.IncomingRequest.Headers.Get(rawHeaderString)
Run Code Online (Sandbox Code Playgroud)
但在 ASP.NET 中,标头位于仅接受标头字符串的 NameValueCollection 中:
HttpContext.Current.Request.Headers[rawHeaderString]
Run Code Online (Sandbox Code Playgroud)
为了将枚举用于 ASP.NET,从枚举 System.Net.HttpRequestHeader 到其标头字符串的映射在哪里?