The HTML video tag src is the network address and cannot be displayed. Solving the problem 403Forbidden

When the video address refers to the external link, 403 forbidden appears, as shown in the figure below.

Solution:
Add the meta attribute referrer to the header.

 <meta name="referrer" content="no-referrer">

Principle analysis:

There is a referrer field in the http request header, which is used to indicate the source address information of the http request.

After getting the referrer value, the server determines whether the request comes from this site.

If not, 403 will be returned to prevent hotlinking of the image.

The reason why 403 appears above is because the request was for resources on someone else's server, but I brought my own referrer information there and was intercepted by the other party's server and returned 403.

On the front end, you can set the referrer policy (source policy) through meta. If the referrer is set to no-referrer, the request will not be sent with the referrer information, and the other server will not be able to intercept it.

content = "attribute value" common are the following:

no-referrer: Do not send Referrer information under any circumstances;

no-referrer-when-downgrade: Do not send Referrer information only when the protocol is downgraded (such as jumping from an HTTPS page to an HTTP page). Is the default policy of most browsers.

Origin: Send referrer information that only contains the host part, that is, the URL that only contains the protocol and domain name, and does not include the latter part of the domain name. For example, the source web page URL is https://baidu.com/1.html, but the referrer value is only Contains http://www.baidu.com;

origin-when-cross-origin: Only when cross-domain access occurs, the Referer information containing only the host is sent, but it is still complete in the same domain. Only when the protocol, domain name and port are consistent, the browser considers it to be the same. area.

unsafe-url: All referrer information is sent, which is the loosest and most unsafe strategy.

Kind tips:

1. The <meta> tag of the referrer attribute needs to be placed between <head> ...</head>. If it appears in the wrong position, it will be ignored.

2. If there is no content attribute, or the content attribute value is empty, it will also be ignored.

3. If the value behind the content attribute is illegal, the browser will automatically select no-referrer.

Guess you like

Origin blog.csdn.net/pinhmin/article/details/132760011