Javascript Google.com 和 clients1.google.com/generate_204

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1989214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 22:16:56  来源:igfitidea点击:

Google.com and clients1.google.com/generate_204

javascripthttphttp-headers

提问by David Murdoch

I was looking into google.com's Net activity in firebug just because I was curious and noticed a request was returning "204 No Content."

我正在查看 google.com 在 firebug 中的网络活动,只是因为我很好奇并注意到请求返回“204 No Content”。

It turns out that a 204 No Content "is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view." Whatever.

事实证明,“204 No Content”主要是为了允许在不改变用户代理的活动文档视图的情况下进行操作的输入,尽管任何新的或更新的元信息都应该应用于当前在用户代理的活动文档中的文档。看法。” 任何。

I've looked into the JS source code and saw that "generate_204" is requested like this:

我查看了 JS 源代码,看到“generate_204”是这样请求的:

(new Image).src="http://clients1.google.com/generate_204"

No variable declaration/assignment at all.

根本没有变量声明/赋值。

My first idea is that it was being used to track if Javascript is enabled. But the "(new Image).src='...'" call is called from a dynamically loaded external JS file anyway, so that would be pointless.

我的第一个想法是它被用来跟踪是否启用了 Javascript。但是无论如何,“(new Image).src='...'”调用是从动态加载的外部 JS 文件中调用的,所以这毫无意义。

Anyone have any ideas as to what the point could be?

任何人对这点可能有什么想法?

UPDATE

更新

"/generate_204" appears to be available on many google services/servers (e.g., maps.google.com/generate_204, maps.gstatic.com/generate_204, etc...).

“/generate_204”似乎在许多谷歌服务/服务器上可用(例如,maps.google.com/generate_204、maps.gstatic.com/generate_204 等...)。

You can take advantage of this by pre-fetching the generate_204 pages for each google-owned service your web app may use. Like This:

您可以通过为您的网络应用程序可能使用的每个谷歌拥有的服务预取 generate_204 页面来利用这一点。像这样:

window.onload = function(){
    var two_o_fours = [
        // google maps domain ...
        "http://maps.google.com/generate_204",

        // google maps images domains ... 
        "http://mt0.google.com/generate_204",
        "http://mt1.google.com/generate_204",
        "http://mt2.google.com/generate_204",
        "http://mt3.google.com/generate_204",

        // you can add your own 204 page for your subdomains too!
        "http://sub.domain.com/generate_204"
    ];
    for(var i = 0, l = two_o_fours.length; i < l; ++i){
        (new Image).src = two_o_fours[i];
    }
};

采纳答案by Matthew Crumley

Like Snukker said, clients1.google.com is where the search suggestions come from. My guess is that they make a request to force clients1.google.com into your DNS cache before you need it, so you will have less latency on the first "real" request.

就像 Snukker 所说,clients1.google.com 是搜索建议的来源。我的猜测是,他们会在您需要之前请求强制 clients1.google.com 进入您的 DNS 缓存,因此您在第一个“真实”请求上的延迟会更少。

Google Chrome already does that for any links on a page, and (I think) when you type an address in the location bar. This seems like a way to get all browsers to do the same thing.

谷歌浏览器已经对页面上的任何链接执行了此操作,并且(我认为)当您在地址栏中键入地址时。这似乎是让所有浏览器都做同样事情的一种方式。

回答by Morphius

I found this old Thread while google'ing for generate_204 as Android seems to use this to determine if the wlan is open (response 204 is received) closed (no response at all) or blocked (redirect to captive portal is present). In that case a notification is shown that a log-in to WiFi is required...enter image description here

我在谷歌搜索 generate_204 时发现了这个旧线程,因为 Android 似乎使用它来确定 wlan 是打开(收到响应 204)关闭(根本没有响应)还是被阻止(重定向到强制门户)。在这种情况下,会显示需要登录 WiFi 的通知...在此处输入图片说明

回答by tonhozi

In the event that Chrome detects SSL connection timeouts, certificate errors, or other network issues that might be caused by a captive portal (a hotel's WiFi network, for instance), Chrome will make a cookieless request to http://www.gstatic.com/generate_204and check the response code. If that request is redirected, Chrome will open the redirect target in a new tab on the assumption that it's a login page. Requests to the captive portal detection page are not logged.

如果 Chrome 检测到 SSL 连接超时、证书错误或其他可能由强制门户(例如酒店的 WiFi 网络)引起的网络问题,Chrome 将向http://www.gstatic发出无 cookie 请求。 com/generate_204并检查响应代码。如果该请求被重定向,Chrome 将假设它是一个登录页面,在新选项卡中打开重定向目标。不会记录对强制门户检测页面的请求。

Font: Google Chrome Privacy Whitepaper

字体:Google Chrome 隐私白皮书

回答by Suresh

Google is using this to detect whether the device is online or in captive portal.

谷歌正在使用它来检测设备是在线还是在强制门户中。

Shill, the connection manager for Chromium OS, attempts to detect services that are within a captive portal whenever a service transitions to the ready state. This determination of being in a captive portal or being online is done by attempting to retrieve the webpage http://clients3.google.com/generate_204. This well known URL is known to return an empty page with an HTTP status 204. If for any reason the web page is not returned, or an HTTP response other than 204 is received, then shill marks the service as being in the portal state.

Chromium OS 的连接管理器 Shill 尝试在服务转换到就绪状态时检测强制门户内的服务。通过尝试检索网页http://clients3.google.com/generate_204来确定是否处于强制门户中或在线。众所周知,这个众所周知的 URL 会返回一个带有 HTTP 状态 204 的空页面。如果由于任何原因没有返回网页,或者收到了 204 以外的 HTTP 响应,则 shill 将服务标记为处于门户状态。

Here is the relevant explanation from the Google Chrome Privacy Whitepaper:

以下是Google Chrome 隐私白皮书中的相关解释:

In the event that Chrome detects SSL connection timeouts, certificate errors, or other network issues that might be caused by a captive portal (a hotel's WiFi network, for instance), Chrome will make a cookieless request to http://www.gstatic.com/generate_204and check the response code. If that request is redirected, Chrome will open the redirect target in a new tab on the assumption that it's a login page. Requests to the captive portal detection page are not logged.

如果 Chrome 检测到 SSL 连接超时、证书错误或其他可能由强制门户(例如酒店的 WiFi 网络)引起的网络问题,Chrome 将向http://www.gstatic发出无 cookie 请求。 com/generate_204并检查响应代码。如果该请求被重定向,Chrome 将假设它是一个登录页面,在新选项卡中打开重定向目标。不会记录对强制门户检测页面的请求。

More info: http://www.chromium.org/chromium-os/chromiumos-design-docs/network-portal-detection

更多信息:http: //www.chromium.org/chromium-os/chromiumos-design-docs/network-portal-detection

回答by Snukker

204 responses are sometimes used in AJAX to track clicks and page activity. In this case, the only information being passed to the server in the get request is a cookie and not specific information in request parameters, so this doesn't seem to be the case here.

有时在 AJAX 中使用 204 响应来跟踪点击和页面活动。在这种情况下,在 get 请求中传递给服务器的唯一信息是 cookie 而不是请求参数中的特定信息,所以这里似乎不是这种情况。

It seems that clients1.google.com is the server behind google search suggestions. When you visit http://www.google.com, the cookie is passed to http://clients1.google.com/generate_204. Perhaps this is to start up some kind of session on the server? Whatever the use, I doubt it's a very standard use.

似乎clients1.google.com 是谷歌搜索建议背后的服务器。当您访问http://www.google.com 时,cookie 会传递到http://clients1.google.com/generate_204。也许这是在服务器上启动某种会话?不管有什么用途,我怀疑这是一个非常标准的用途。

回答by divinci

with the massive remit by google to stop both spam and the scraping of their search database, I believe that this is part of the effort to track bots etc.

谷歌为阻止垃圾邮件和搜索数据库的抓取做出了大量的努力,我相信这是跟踪机器人等工作的一部分。

some simple anti bot pseudo could go like this.

一些简单的反机器人伪代码可能会像这样。

On GET (google.*) Save RemoteEndPoint
{
    If RemoteEndPoint GETs (clients1.google.com/generate_204) Then
        Set botAlert_stage1 = false;
    Else
        Set botAlert_stage1 = true;
    End If
}

I also believe that the latest google frontpage 'theme' is also a new tool to help with the anti spam/bot activity.

我也相信最新的谷歌首页“主题”也是一个帮助反垃圾邮件/机器人活动的新工具。

** NOTE ** ipv6.google.com also includes this measure.

** 注意** ipv6.google.com 也包括此措施。

Just my unfounded unproofed two 2p.

只是我的毫无根据的未经证明的两个2p。

回答by motobói

This documents explains:

该文件说明:

http://docs.lib.purdue.edu/cgi/viewcontent.cgi?article=1417&context=ecetr&sei-redir=1

http://docs.lib.purdue.edu/cgi/viewcontent.cgi?article=1417&context=ecetr&sei-redir=1

(Search for generate204)

搜索 generate204

Relevant section:

相关栏目:

Among the different objects, a javascript function triggers a generate204request sent to the video server that is supposed to serve the video. This starts the video prefetch, which has two main goals: first, it forces the client to perform the DNS resolution of the video server name. Second, it forces the client to open a TCP connection toward the video server. Both help to speed-up the video download phase.

In addition, the generate204request has exactly the same format and options of the real video download request, so that the video server is eventually warned that a client will possibly download that video very soon. Note that the video server replies with a 204 No Contentresponse, as implied by the command, and no video content is downloaded so far.

在不同的对象中,一个 javascript 函数触发一个generate204请求,该请求发送到应该提供视频的视频服务器。这将启动视频预取,它有两个主要目标:首先,它强制客户端执行视频服务器名称的 DNS 解析。其次,它强制客户端打开一个到视频服务器的 TCP 连接。两者都有助于加快视频下载阶段。

此外,generate204请求与真实视频下载请求具有完全相同的格式和选项,因此最终会警告视频服务器客户端可能很快就会下载该视频。请注意,视频服务器回复了一个204 No Content响应,正如命令所暗示的那样,到目前为止还没有下载任何视频内容。

回答by gnasher729

Many applications access this URL to determine if they have a connection that only leads to a captive portal.

许多应用程序访问此 URL 以确定它们是否具有仅指向强制门户的连接。

The idea is that any captive portal thinks this is a "normal" website, and then redirects you to its portal site, which is returned with a status 200. If an application tries to access any normal website, it is confronted with a totally unexpected response and may have problems figuring out what's wrong. However, with this URL it's easy: If you get status 200, you are inside a captive portal, and you can tell your user to do something about it (usually either log in to the portal using a browser, or turn WiFi off and rely on 3G, if they are using a phone). If you get status 204, you got connected to Google, so your application is actually connected to the internet.

这个想法是任何强制门户都认为这是一个“正常”网站,然后将您重定向到其门户站点,该站点返回状态 200。如果应用程序尝试访问任何正常网站,它会遇到完全出乎意料的响应,并且可能无法找出问题所在。但是,使用此 URL 很容易:如果您获得状态 200,则您处于强制门户内,您可以告诉您的用户对其进行处理(通常使用浏览器登录门户,或关闭 WiFi 并依赖在 3G 上,如果他们使用的是电话)。如果您获得状态 204,则您已连接到 Google,因此您的应用程序实际上已连接到 Internet。

Microsoft and Apple use a slightly different approach; they both have some URLs that return a very specific short text message with a status 200, so instead of accessing the Google url you can for example go to "captive.apple.com" and check for status 200 with data = "Success" and nothing else. If you get status 200 and not exactly that data then you are again in a captive portal.

微软和苹果使用的方法略有不同;它们都有一些 URL 会返回一条状态为 200 的非常具体的短文本消息,因此,您可以访问“captive.apple.com”并检查状态 200(数据 =“成功”),而不是访问 Google url。没有其他的。如果您获得状态 200 而不是该数据,那么您将再次处于强制门户中。

回答by digitalsanctum

I found this blog post which explains that it's used to record clicks. Without official word from Google it could be used any number of things.

我发现这篇博文解释了它用于记录点击次数。没有来自谷歌的官方消息,它可以用于任何数量的东西。

http://mark.koli.ch/2009/03/howto-configure-apache-to-return-a-http-204-no-content-for-ajax.html

http://mark.koli.ch/2009/03/howto-configure-apache-to-return-a-http-204-no-content-for-ajax.html

回答by Kranthi

The generate 204 might be dynamically loading the suggestions of search criteria. AS i can see from my load test script, this is seemingly responsible for every server call each time the user types into the text box

生成器204可能正在动态加载搜索标准的建议。正如我从我的负载测试脚本中看到的那样,这似乎负责每次用户在文本框中键入时的每个服务器调用