我注意到一个奇怪的警告信息,当使用谷歌chrome检查器(F12)查看下载的资源:
注意显示临时标题
我发现一些可能相关的东西,网络面板:添加临时请求头的警告,但我不能完全理解它。相关问题可以发现Chrome块请求以及XMLHttpRequest无法加载。未加载的资源显示警告:显示临时标头。
与第一个问题类似,我的资源被阻塞了,但后来自动加载了相同的资源。不像第二个问题,我不想解决任何问题;我想知道这条信息是什么意思以及我为什么收到它。
我注意到一个奇怪的警告信息,当使用谷歌chrome检查器(F12)查看下载的资源:
注意显示临时标题
我发现一些可能相关的东西,网络面板:添加临时请求头的警告,但我不能完全理解它。相关问题可以发现Chrome块请求以及XMLHttpRequest无法加载。未加载的资源显示警告:显示临时标头。
与第一个问题类似,我的资源被阻塞了,但后来自动加载了相同的资源。不像第二个问题,我不想解决任何问题;我想知道这条信息是什么意思以及我为什么收到它。
当前回答
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.
其他回答
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.
这可能是CORS的问题。 尝试为你的api启用CORS。
为WebApi
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
我遇到过这个,当我从https切换到http时,它就消失了。我们在开发中使用的SSL证书没有经过第三方的验证。它们只是本地生成的开发证书。
同样的调用在Chrome Canary和Firefox中也能正常运行。这些浏览器似乎不像Chrome那样严格要求SSL证书。调用将失败在Chrome与“警告:临时头…”消息。
我认为/希望当我们在阶段和prod中使用合法的SSL证书时,我们将不再在Chrome中看到这种行为。
如果响应无效并因此被浏览器删除,也会出现此警告消息。
在我的例子中,请求被正确地发送到服务器,服务器端代码随后产生一个错误,我的自定义错误处理在HTTP状态消息字段中返回错误消息。但是客户端没有收到此错误,因为错误消息中的无效字符(此处描述为http://aspnetwebstack.codeplex.com/workitem/1386)导致响应报头损坏。
我的MEAN应用程序也有类似的问题。在我的情况下,这个问题只发生在一个get请求中。我尝试删除广告块,尝试清除缓存,并尝试与不同的浏览器。没有什么帮助。
最后,我发现api试图返回一个巨大的JSON对象。当我尝试发送一个小对象时,它工作得很好。最后,我改变了我的实现,返回一个缓冲区而不是JSON。
我希望expressJS在这种情况下抛出一个错误。