我不知道这是否是http规范中的错误或功能,或者我不理解正常的事情.
我有一个资源,每周最多更改一次,在本周开始.如果它没有改变,那么前一周的资源将持续整周有效.
(对于我们所有的测试,我们将一周时间修改为五分钟,但我认为我们的观察结果仍然有效).
首先,我们使用标头发送资源Expires: next Monday.浏览器从缓存中检索的整个星期.如果在星期一我们有一个新资源,那么它将使用新的标题进行检索,一切正常.
资源未续订时会出现此问题.响应条件获取我们的应用程序(Java + Tomcat)发送带有Expires: next Monday但没有正文的新标头.但我们的前端服务器(apache)删除了此标头,因为规范说如果资源没有更改,则不应发送新标头.所以现在永远(直到资源发生变化),当我们希望它继续直接从缓存中提供时,浏览器将发送条件获取.
是否有符合规范的方式更新标题而不更新正文?(或再次发送)
和subquestion:如何使apache传递tomcat的标头?
在我的例子中,我有Glassfish 3.1.1/Mojarra 2.1.3
我可以在网络侦听器中删除Glassfish管理控制台中的X-Powered-By(因此它不会显示长文本:
Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.1 Java/Sun Microsystems Inc./1.6)
Run Code Online (Sandbox Code Playgroud)
但它仍然显示(是的,两次):
X-Powered-By: JSF/2.0
X-Powered-By: JSF/2.0
Run Code Online (Sandbox Code Playgroud)
我使用Jersey和JAXB来公开一些Web服务,并使用@WebServlet Annotation部署了一些servlet,但我不认为它们会添加任何内容.
它不是由mod_jk或Apache生成的,因为即使直接连接到应用程序端口,我也会获得这些头文件(localhost:8080)
是否有典型的模块可以在Glassfish中执行此操作?如何删除这些标题?
谢谢
我正在向google封闭编译器API服务发出请求:
$content = file_get_contents('file.js');
$url = 'http://closure-compiler.appspot.com/compile';
$post = true;
$postData = array('output_info' => 'compiled_code', 'output_format' => 'text', 'compilation_level' => 'SIMPLE_OPTIMIZATIONS', 'js_code' => urlencode($content)));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($post) {
curl_setopt($ch, CURLOPT_POST, $post);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8'));
Run Code Online (Sandbox Code Playgroud)
但请求失败,我从谷歌收到此错误消息:
Error(18): Unknown parameter in Http request: '------------------------------0f1f2f05fb97
Content-Disposition: form-data; name'.
Error(13): No output information to produce, yet compilation was requested.
Run Code Online (Sandbox Code Playgroud)
我查看了标题,并发送了此Content-Type标头:
application/x-www-form-urlencoded; charset=UTF-8; boundary=----------------------------0f1f2f05fb97
Run Code Online (Sandbox Code Playgroud)
不确定添加的边界是否正常?我如何防止这种情况,因为谷歌似乎不喜欢它?
谢谢你,韦斯利
我遇到了与本文所述相同的问题:
也就是说,一旦我使用Google Calendar API(v3)创建活动并更新一次,我就无法再更新活动.当我尝试时,我得到一个400 - 无效的值响应.(FWIW我在PHP工作).
在我上面提到的帖子中提供了一个主导,我尝试使用etags解决问题(尽管我承认他们的工作方式是有限的).基本上,在事件更新时,API会在其响应中返回一个etag,我现在将其保存在我的数据库中.然后,对于后续(n> 1)更新,我从数据库中提取当前etag并将其包含在http标头中:
Content-Type: application/json
Authorization: OAuth [token]
If-Match: [etag]
Run Code Online (Sandbox Code Playgroud)
以下是"更新条目"标题下的信息:http://code.google.com/apis/gdata/docs/2.0/reference.html#ResourceVersioning
旁注:在上面的google ref中,If-Match标题显示为
If-Match: "S0wCTlpIIip7ImA0X0QI"
Run Code Online (Sandbox Code Playgroud)
在etag周围加上双引号.我用双引号将etags保存在数据库中,就像我在第一次更新响应中收到它们一样.使用curl_setopt/HTTPHEADER添加到标题时,是否需要转义引号或其他内容?
尽管实现了这个etag If-Match的东西,我仍然得到相同的400 - 无效的值响应.我知道我的请求主体是有效的,因为第一次更新工作正常.围绕后续更新还有一些其他问题.
任何帮助非常感谢.
我想知道是否有任何方法可以在Get ajax请求(xhr.get)中设置我自己的自定义http标头,该请求会自动执行JsonRest存储.
有一个相关的主题,但没有一个很好的解决方案: 带有自定义HTTP标头的Dojo数据网格
我已经在'dojo.store.JsonRest'中看到了包含构造函数的JsonRest实现,如果我们能够做到或不做(我不这么认为),这一点并不明显.正在使用的JsonRest存储示例:
var store = new JsonRestStore({target: "/Table/" });
Run Code Online (Sandbox Code Playgroud) 当缓存与HTML页面must-revalidate,这意味着浏览器必须检查被定义的任何更新Last-Modified或Etag.然而,问题是,之前max-age,浏览器不会与该网站进行任何连接读取HTTP标头(分析Last-Modified和Etag)?
如何强制浏览器做一个简单的连接到阅读(至少)HTTP读者从缓存中加载页面的?
我不明白的用法must-revalidate!以前检查更新是否有责任max-age?因为在到达之后max-age,浏览器将从网站读取并且从不使用本地缓存.
我试图在数据库结果为空(这是产品页面)时发送两者.
我现在使用的代码,有效:
header("Status: 404 Not Found");
include_once("404.html");
exit;
Run Code Online (Sandbox Code Playgroud)
我最初尝试过的代码不起作用:
header("Status: 404 Not Found");
header("Location: 404.html");
exit;
Run Code Online (Sandbox Code Playgroud)
使用后面的代码,我可以使用其中之一,但不能同时使用两者.换句话说,我可以发送404标头并看到它显示在Wireshark中,或者我可以发送Location标头并重定向,但是如果我尝试发送两者,则只会发送404并且Location头也不会重定向.
我已经用可行的解决方案解决了问题,但我想知道为什么会这样.
带有FastCGI的Linux上的PHP 5.2.
谢谢.
我正在向服务器发送数据,我想收到HTTP响应状态,以检查此状态并提供适当的视图
@RequestMapping(method = RequestMethod.POST)
public String Login(@ModelAttribute("Attribute") Login login, Model model,HttpServletRequest request) {
// Prepare acceptable media type
ArrayList<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(MediaType.APPLICATION_XML);
// Prepare header
HttpHeaders headers = new HttpHeaders();
headers.setAccept(acceptableMediaTypes);
HttpEntity<Login> entity = new HttpEntity<Login>(login, headers);
// Send the request as POST
try {
ResponseEntity<Login> result = restTemplate.exchange("http://www.../user/login/",
HttpMethod.POST, entity, Login.class);
} catch (Exception e) {
}
//here i want to check the received status
if(status=="OK"){
return "login"
}
else
return "redirect:/home";
}
Run Code Online (Sandbox Code Playgroud) 我想从C#发出HTTP Post请求.此请求具有自定义标头.当我尝试启动我的程序时,我收到了以下异常:
意大利:
Questa intestazione deve essere modificata utilizzandolaproprietàoil metodo appropriato.Nome参数:名称
英语:
必须使用适当的属性或方法修改此标头.
在线: request.Headers.Add("Content-Type", "text/x-gwt-rpc; charset=utf-8");
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Collections.Specialized;
using System.IO;
using System.Text.RegularExpressions;
using System.Dynamic;
using System.Collections;
using System.Collections.ObjectModel;
using System.Net.Security;
using System.Web;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
WebRequest request = WebRequest.Create("http://www.androidlost.com/androidlost/greet");
request.Method = "POST";
request.Headers.Add("Content-Type", "text/x-gwt-rpc; charset=utf-8");
string postData = "Test";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream(); …Run Code Online (Sandbox Code Playgroud) 在我的CodeIgniter网站中,当在Chrome中查看时,控制台会显示警告
style.css interpreted as IMAGE but transferred with MIME type text/css
页面按照我的预期呈现,但是当我右键单击并检查任何元素时,它的"计算样式"显示为空白,使调试变得困难.
这就是我提供CSS文件的方式
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title; ?></title>
<link rel="icon" type="image/png" href="<?= base_url('assets/images/favicon.png'); ?>" />
<link rel="stylesheet" type="text/css" media="all" href="<?= base_url('assets/css/style.css');?>" />
<link href='http://fonts.googleapis.com/css?family=Oswald:400,700|Open+Sans+Condensed:300,300italic,700' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)
使用Chrome扩展程序,我在请求style.css时监控了正在发送的标头,这就是我得到的:

编辑
这是在共享godaddy主机上的LAMP服务器上.我的重写htaccess只包含以下重写规则:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /
RewriteRule ^(.*)$ /index.php?$1 [L]
Run Code Online (Sandbox Code Playgroud) http-headers ×10
http ×3
php ×3
curl ×2
java ×2
ajax ×1
apache2 ×1
c# ×1
caching ×1
codeigniter ×1
css ×1
dojo ×1
etag ×1
glassfish-3 ×1
google-api ×1
header ×1
jsf-2 ×1
json ×1
spring-mvc ×1
store ×1
tomcat ×1