provisional headers are shown
程序员文章站
2022-07-11 07:50:47
...
问题描述:
一个ajax请求失败,在浏览器的表现是HTTP request Headers中有provisional headers are shown,而且在network选项卡中,显示网络请求status为failed。首先按照网络上的解释出现provisional headers are shown 表明当前请求的数据并没有发送到服务器端(实际并不是如此)
出现上述问题一般有两种原因:
1. 请求从缓存中取数据
2. 请求由于某些原因被中断,例如:在iframe中ajax请求发送之前,iframe被删除;在form表单提交同时ajax也发出请求;还有就是ajax请求超时;
但是通过代码并没有发现上述两点问题,接着按照网络上说的使用chrome自带的工具去查看具体的网络请求事件。
在浏览器中输入chrome://net-internals,找到event选项
查看event记录: 看粗体部分
从中可以看到前边有正常的请求数据, 继续往后看在最后边有一个网络响应而且使从服务器端返回来的。 此处竟然有302网络响应结果返回,那么问题来了。 怎么会表现为状态为failed而不是302呢? 302这个状态在上述日志中只是一个中间结果,在日志的最后可以看到请求被CANCELLED以及ERR_ABORTED了。 具体啥原因,先不研究了。
既然返回了302,那么一定是服务器端发生了异常。 经确认的确是服务端数据错误,导致服务器给出了302的信息。
总结:
在浏览器中发现provisional headers are shown,也并不一定就说明问题只在前端不在服务器端。
一个ajax请求失败,在浏览器的表现是HTTP request Headers中有provisional headers are shown,而且在network选项卡中,显示网络请求status为failed。首先按照网络上的解释出现provisional headers are shown 表明当前请求的数据并没有发送到服务器端(实际并不是如此)
出现上述问题一般有两种原因:
1. 请求从缓存中取数据
2. 请求由于某些原因被中断,例如:在iframe中ajax请求发送之前,iframe被删除;在form表单提交同时ajax也发出请求;还有就是ajax请求超时;
但是通过代码并没有发现上述两点问题,接着按照网络上说的使用chrome自带的工具去查看具体的网络请求事件。
在浏览器中输入chrome://net-internals,找到event选项
查看event记录: 看粗体部分
237851: URL_REQUEST http://pay.gyyx.cn/GyyxCardPay/PayGYB?r=0.519311266924479 Start Time: 2017-09-22 15:51:35.169 t=12472482 [st= 0] +REQUEST_ALIVE [dt=51] --> priority = "HIGHEST" --> url = "http://pay.gyyx.cn/GyyxCardPay/PayGYB?r=0.519311266924479" t=12472483 [st= 1] URL_REQUEST_DELEGATE [dt=0] t=12472483 [st= 1] +URL_REQUEST_START_JOB [dt=50] --> load_flags = 49408 (IGNORE_LIMITS | MAYBE_USER_GESTURE | VERIFY_EV_CERT) --> method = "POST" --> upload_id = "0" --> url = "http://pay.gyyx.cn/GyyxCardPay/PayGYB?r=0.519311266924479" t=12472483 [st= 1] URL_REQUEST_DELEGATE [dt=0] t=12472483 [st= 1] HTTP_CACHE_GET_BACKEND [dt=0] t=12472483 [st= 1] +HTTP_STREAM_REQUEST [dt=0] t=12472483 [st= 1] HTTP_STREAM_JOB_CONTROLLER_BOUND --> source_dependency = 237853 (HTTP_STREAM_JOB_CONTROLLER) t=12472483 [st= 1] HTTP_STREAM_REQUEST_BOUND_TO_JOB --> source_dependency = 237854 (HTTP_STREAM_JOB) t=12472483 [st= 1] -HTTP_STREAM_REQUEST t=12472483 [st= 1] +UPLOAD_DATA_STREAM_INIT [dt=0] t=12472483 [st= 1] UPLOAD_DATA_STREAM_INIT [dt=0] --> is_chunked = false --> net_error = 0 (?) --> total_size = 195 t=12472483 [st= 1] -UPLOAD_DATA_STREAM_INIT --> is_chunked = false --> net_error = 0 (?) --> total_size = 195 t=12472483 [st= 1] +HTTP_TRANSACTION_SEND_REQUEST [dt=1] t=12472483 [st= 1] HTTP_TRANSACTION_SEND_REQUEST_HEADERS -->[b] POST http://pay.gyyx.cn/GyyxCardPay/PayGYB?r=0.519311266924479 HTTP/1.1 Host: pay.gyyx.cn Proxy-Connection: keep-alive Content-Length: 195 Accept: application/json, text/javascript, */*; q=0.01 Origin: http://pay.gyyx.cn X-Requested-With: XMLHttpRequest User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36 Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Referer: http://pay.gyyx.cn/gamepay/paygyb Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.8 Cookie: [352 bytes were stripped][/b] t=12472484 [st= 2] HTTP_TRANSACTION_SEND_REQUEST_BODY --> did_merge = false --> is_chunked = false --> length = 195 t=12472484 [st= 2] +UPLOAD_DATA_STREAM_READ [dt=0] --> current_position = 0 t=12472484 [st= 2] UPLOAD_DATA_STREAM_READ [dt=0] --> current_position = 0 t=12472484 [st= 2] -UPLOAD_DATA_STREAM_READ t=12472484 [st= 2] UPLOAD_DATA_STREAM_READ [dt=0] --> current_position = 195 t=12472484 [st= 2] -HTTP_TRANSACTION_SEND_REQUEST t=12472484 [st= 2] +HTTP_TRANSACTION_READ_HEADERS [dt=48] t=12472484 [st= 2] HTTP_STREAM_PARSER_READ_HEADERS [dt=47] t=12472531 [st=49] HTTP_STREAM_PARSER_READ_HEADERS [dt=1] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_STREAM_PARSER_READ_HEADERS [dt=0] t=12472532 [st=50] HTTP_TRANSACTION_READ_RESPONSE_HEADERS -->[b] HTTP/1.1 302 Found Content-Length: 189 Cache-Control: private Content-Type: text/html; charset=utf-8 Date: Fri, 22 Sep 2017 07:51:36 GMT Gy-Log-Id: vQN3u2-8a902410711a9-029-3MziEf-8afcd Keep-Alive: timeout=38 Location: http://static.gyyx.cn/error/index.html?aspxerrorpath=/GyyxCardPay/PayGYB Server: Microsoft-IIS/7.5 Set-Cookie: [55 bytes were stripped] X-Aspnet-Version: 4.0.30319 X-Aspnetmvc-Version: 4.0 X-Powered-By: ASP.NET[/b] t=12472532 [st=50] -HTTP_TRANSACTION_READ_HEADERS t=12472532 [st=50] URL_REQUEST_DELEGATE [dt=0] t=12472532 [st=50] URL_REQUEST_DELEGATE [dt=1] t=12472533 [st=51] [b]CANCELLED[/b] t=12472533 [st=51] -URL_REQUEST_START_JOB --> [b]net_error = -3 (ERR_ABORTED)[/b] t=12472533 [st=51] URL_REQUEST_DELEGATE [dt=0] t=12472533 [st=51] -REQUEST_ALIVE
从中可以看到前边有正常的请求数据, 继续往后看在最后边有一个网络响应而且使从服务器端返回来的。 此处竟然有302网络响应结果返回,那么问题来了。 怎么会表现为状态为failed而不是302呢? 302这个状态在上述日志中只是一个中间结果,在日志的最后可以看到请求被CANCELLED以及ERR_ABORTED了。 具体啥原因,先不研究了。
既然返回了302,那么一定是服务器端发生了异常。 经确认的确是服务端数据错误,导致服务器给出了302的信息。
总结:
在浏览器中发现provisional headers are shown,也并不一定就说明问题只在前端不在服务器端。
推荐阅读
-
php session_start()关于Cannot send session cache limiter - headers already sent错误解决方法
-
Springboot解决ajax+自定义headers的跨域请求问题
-
详解Nginx服务器中HTTP Headers相关的模块配置使用
-
DRF跨域后端解决之django-cors-headers的使用
-
kernel-headers下载
-
The specified CGI application misbehaved by not returning a complete set of HTTP headers
-
PHP使用get_headers函数判断远程文件是否存在的方法
-
setcookie中Cannot modify header information-headers already sent by错误的解决方法详解
-
kernel-headers-2.2.1-4
-
jQuery.Form实现Ajax上传文件同时设置headers的方法