204没有内容

Sometimes you want to send an HTTP request and you don't care about the response. This is often used for logging stuff on the server. Usually you request a 1x1 pixel GIF file and send a bunch of query parameters. E.g. htp://example.org/blank.gif?user=stoyan&browser=msie&creditcard=123JUSTKIDDING567

有时您想发送HTTP请求,而不必关心响应。 这通常用于在服务器上记录内容。 通常,您需要一个1x1像素的GIF文件并发送一堆查询参数。 例如htp://example.org/ blank.gif ?user=stoyan&browser=msie&creditcard=123JUSTKIDDING567

Such 1x1 gifs are often called "web bugs" or "beacons" and sometimes used for sneaky purposes such as checking whether-you-opened-that-email-I-sent-you-that-you-didn't-reply-to-although-I-told-you-it-was-urgent-dammit-now-I'm-gonna-tell-the-boss-yes-this-time-I'm-telling-the-boss!

这样的1x1 gif文件通常被称为“网络错误”或“信标”,有时还用于偷偷摸摸的目的,例如检查您是否打开了电子邮件,是否发送了您未答复的邮件。虽然我告诉你这是紧急的,但现在我要告诉老板了,这一次我是在告诉老板!

Now (after we relax a bit)... instead of having your server send a blank GIF, however small, can you just send.. nothing? Yep, you can. Your server can respond with a "204 No content" header. Cool, eh, especially when you want to squeeze every bit of network traffic?

现在(稍等片刻之后)...而不是让服务器发送空白的GIF,不管它多么小,您可以发送..什么都没有吗? 是的,可以。 您的服务器可以响应“ 204 No content”标头。 太酷了,特别是当您想压缩网络流量的每一点时?

So the example above can look like: htp://example.org/nope.php?user=stoyan&browser=msie&creditcard=123JUSTKIDDING567

因此,上面的示例如下所示: htp://example.org/ nope.php ?user=stoyan&browser=msie&creditcard=123JUSTKIDDING567

And nope.php could be like:

和nope.php可能像:

<?php
// .... log whatever you need to log, then reply:
header("HTTP/1.0 204 No Content");
?>

Here's what this looks like in Net Panel.

这是Net Panel中的外观。

204

And an example in the wild (Google search beacon)

还有一个例子(Google搜索信标)

Google search beacon

Another application of 204s I was thinking could be favicons. If you don't want to deal with favicons, but you don't want to respond with a 404 Not Found either, you can just configure Apache to send 204 to favicon requests. Could be useful when your application generates subdomains for your users, since the browser will request the favicon from each subdomian (unless you have a link-ed favicon).

我在想的204s的另一个应用可能是网站图标。 如果您不想处理favicon,但也不想使用404 Not Found进行响应,则可以将Apache配置为将204发送到favicon请求。 当您的应用程序为您的用户生成子域时,此功能可能很有用,因为浏览器将向每个子域请求收藏夹图标(除非您具有链接的收藏夹图标)。

Tell your friends about this post on Facebook and Twitter

FacebookTwitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/204-no-content/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值