我注意到一个奇怪的警告信息,当使用谷歌chrome检查器(F12)查看下载的资源:

注意显示临时标题

我发现一些可能相关的东西,网络面板:添加临时请求头的警告,但我不能完全理解它。相关问题可以发现Chrome块请求以及XMLHttpRequest无法加载。未加载的资源显示警告:显示临时标头。

与第一个问题类似,我的资源被阻塞了,但后来自动加载了相同的资源。不像第二个问题,我不想解决任何问题;我想知道这条信息是什么意思以及我为什么收到它。


当前回答

尝试用ctrl + shift +F5重新加载页面,然后再次检查请求头

没有显示完整的头文件,因为有可能请求没有发送到服务器,而是直接从浏览器的缓存(例如使用service worker)提供服务

其他回答

My situation is cross-origin related. Situation: Browser sends OPTIONS request before sending the real request like GET or POST. Backend developer forgets to deal with the OPTIONS request, letting it go through the service code, making the processing time too long. Longer than the timeout setting I wrote in the axios initialization, which is 5000 milliseconds. Therefore, the real request couldn't be sent, and then I encountered the provisional headers are shown problem. Solution: When it comes to OPTIONS request, backend api just return result, it makes the request faster and the real request can be sent before timeout.

我相信当实际的请求没有发送时就会发生这种情况。通常在加载缓存资源时发生。

在我的案例中,原因是AdBlock扩展。

向服务器的请求通过了,我得到了响应,但由于“临时头部..”显示在Dev工具中,我无法看到请求cookie。禁用AdBlock后,警告消失了,开发工具开始再次显示cookie。

为了使更改生效,还需要关闭Dev工具并刷新页面

如果您正在开发Asp。Net Mvc应用程序,你试图返回一个JsonResult在你的控制器,确保你添加了JsonRequestBehavior。AllowGet到Json方法。这为我解决了问题。

public JsonResult GetTaskSubCategories(int id)
{
    var subcategs = FindSubCategories(id);

    return Json(subcategs, JsonRequestBehavior.AllowGet);  //<-- Notice it has two parameters
}

当托管在HTTPS上的网站调用托管在HTTP上的WebApi时,可以显示“警告:临时头部显示”消息。你可以检查所有Api是否都是HTTPS。浏览器阻止对不安全资源的调用。当使用FETCH API对HTTP进行域划分时,您可以在代码中看到类似的消息。

混合内容:“https://website.com”的页面通过HTTPS加载,但请求了一个不安全的资源“http://webapi.com”。此请求已被阻止;内容必须通过HTTPS提供。