简体   繁体   English

从URL获取会话的到期时间

[英]Fetching expiry of the session from URL

I'm trying to fetch information from a URL , ie to know When the session time has expired from URL? 我正在尝试从URL获取信息,即知道会话时间何时从URL到期? For example, if you trying to connect to a URL and downloading a file with IDM from Mediafire, then you pause it. 例如,如果您尝试连接到URL并从Mediafire用IDM下载文件,则可以暂停它。 After 4 hours since your first connection to the Mediafire's URL , you're trying to re-connect and resume your download. 自您首次与Mediafire的URL建立连接4个小时后,您正尝试重新连接并恢复下载。 Unfortunately, you get a message saying: 不幸的是,您收到一条消息:

403: Forbidden. 403:禁止 You don't have permission to access file.zip on this server. 您无权访问此服务器上的file.zip。

or this message: 或此消息:

Probably this site uses temporary links that cannot be requested twice or expire after some time when session is completed. 可能此站点使用的临时链接不能被请求两次,也不能在会话完成后的一段时间后过期。

It means that Mediafire gives us max time to re-connect. 这意味着Mediafire给了我们最大的重新连接时间。 So you have to resume your download in that interval. 因此,您必须在该时间间隔内恢复下载。

I have tried: 我努力了:

HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.connect();
String exp = urlConnection.getHeaderField("Expires");
System.out.println("Expire date: " + exp);

Output: 输出:

Expire date: null // while responseCode is 200 OK

Sometimes, with different URL , I got Tue, 03 Nov 2015 03:41:09 PST . 有时,使用不同的URL ,我会收到Tue, 03 Nov 2015 03:41:09 PST

So, how do I know when the session time has expired certainly? 那么,我怎么知道会话时间肯定已过期?

Thank in advance. 预先感谢。

According to RFC there is not always a expires header field. 根据RFC,并不总是有过期标头字段。

Section 5.3 第5.3节

An origin server without a clock MUST NOT generate an Expires field unless its value represents a fixed time in the past (always expired) or its value has been associated with the resource by a system or user with a reliable clock. 没有时钟的原始服务器不得生成Expires字段,除非其值表示过去的固定时间(总是过期)或者其值已由具有可靠时钟的系统或用户与资源相关联。

Furthermore it defines the Freshness in 4.2 此外,它在4.2中定义了新鲜度

If an origin server wishes to force a cache to validate every request, it can assign an explicit expiration time in the past to indicate that the response is already stale. 如果源服务器希望强制缓存验证每个请求,则它可以分配过去的显式到期时间以指示响应已过时。 Compliant caches will normally validate a stale cached response before reusing it for subsequent requests (see Section 4.2.4). 兼容的缓存通常会先验证过时的缓存响应,然后再将其用于后续请求(请参阅第4.2.4节)。

Since origin servers do not always provide explicit expiration times, caches are also allowed to use a heuristic to determine an expiration time under certain circumstances (see Section 4.2.2). 由于原始服务器并不总是提供明确的到期时间,因此在某些情况下,还允许缓存使用启发式方法来确定到期时间(请参阅第4.2.2节)。

So in order to get a somewhat reliable headerfield you can calculate it 因此,为了获得可靠的标头字段,您可以对其进行计算

Since origin servers do not always provide explicit expiration times, a cache MAY assign a heuristic expiration time when an explicit time is not specified, employing algorithms that use other header field values (such as the Last-Modified time) to estimate a plausible expiration time. 由于原始服务器并不总是提供明确的到期时间,因此在未指定明确时间的情况下,缓存可以分配启发式到期时间,采用使用其他报头字段值(例如Last-Modified time)的算法来估计可能的到期时间。 。 This specification does not provide specific algorithms, but does impose worst-case constraints on their results. 该规范未提供特定的算法,但对结果施加了最坏情况的约束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM