如何从 HTTP header 正确解析 base URL?
How to correctly parse base URL from HTTP header?
The base URL can be given by an HTTP header (see [RFC2068]).
我收到的header是:
HTTP/1.1 301 Moved Permanently
Date: Tue, 23 Jan 2018 14:12:27 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.4.16
X-Powered-By: PHP/5.4.16
Location: https://www.meetangee.com/
Content-Length: 0
Content-Type: text/html; charset=UTF-8
基数URL是Location
header指定的URL吗?如果是这样,我应该只解析 Location:
之后的字符直到行尾,还是有更简单的方法来获取基础 URL?
编辑: 的答案与我链接的参考相反,所以如果它是正确的(我不假设),那么我希望某些来源表明我链接的参考不正确。
The base URL can be given by an HTTP header (see [RFC2068]).
直到并包括 RFC 2616, but is no longer true starting with RFC 7231. See my answer to Is there an HTTP header to say what base URL to use for relative links? 的详细信息都是如此。
Is the base URL the URL specified by the Location
header?
没有。 Location
header 用于 3xx
重定向。 User-Agent 意味着通过向指定的 URL 发送新请求来遵循重定向。一些重定向是临时的,因为原来的 URL 应该继续用于同一实体的未来请求。一些重定向是永久性的,因为原来的 URL 不应再使用,取而代之的是新的 URL.
If so, should I just parse the characters after Location:
until end of line, or is there an even simpler way how to get the base URL?
实体的基础 URL 是用于请求实体的最终 non-redirect URL,除非实体本身另有指定(例如在 <base>
元素中在 HTML).
The base URL can be given by an HTTP header (see [RFC2068]).
我收到的header是:
HTTP/1.1 301 Moved Permanently
Date: Tue, 23 Jan 2018 14:12:27 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.4.16
X-Powered-By: PHP/5.4.16
Location: https://www.meetangee.com/
Content-Length: 0
Content-Type: text/html; charset=UTF-8
基数URL是Location
header指定的URL吗?如果是这样,我应该只解析 Location:
之后的字符直到行尾,还是有更简单的方法来获取基础 URL?
编辑: 的答案与我链接的参考相反,所以如果它是正确的(我不假设),那么我希望某些来源表明我链接的参考不正确。
The base URL can be given by an HTTP header (see [RFC2068]).
直到并包括 RFC 2616, but is no longer true starting with RFC 7231. See my answer to Is there an HTTP header to say what base URL to use for relative links? 的详细信息都是如此。
Is the base URL the URL specified by the
Location
header?
没有。 Location
header 用于 3xx
重定向。 User-Agent 意味着通过向指定的 URL 发送新请求来遵循重定向。一些重定向是临时的,因为原来的 URL 应该继续用于同一实体的未来请求。一些重定向是永久性的,因为原来的 URL 不应再使用,取而代之的是新的 URL.
If so, should I just parse the characters after
Location:
until end of line, or is there an even simpler way how to get the base URL?
实体的基础 URL 是用于请求实体的最终 non-redirect URL,除非实体本身另有指定(例如在 <base>
元素中在 HTML).