简体   繁体   English

来自 JavaScript 的协议版本获取响应

[英]Protocol version from JavaScript Fetch responses

I was just playing withFetch and noticed it seemed impossible to get the protocol version from the response start line .我只是在玩Fetch ,发现从响应开始行获取协议版本似乎是不可能的。 During an HTTP request the first line of a response could look like this:在 HTTP 请求期间,响应的第一行可能如下所示:

HTTP/1.1 404 Not Found

Basically, I am looking for a way to get the HTTP/1.1 part of the first line.基本上,我正在寻找一种方法来获取第一行的HTTP/1.1部分。

I was able to find the Response.status and Response.statusText properties, but is there a way to get either the first line (which does not seem to be part of Response.headers ) or the protocol version directly?我能够找到Response.statusResponse.statusText属性,但是有没有办法直接获取第一行(这似乎不是Response.headers的一部分)或协议版本?

The short answer is: No , it's not possible.简短的回答是:,这是不可能的。

I could actually not find details on the "long answer" and why this information was unavailable.我实际上找不到有关“长答案”的详细信息以及为什么无法获得此信息。

var o_res = await fetch("url...");
o_res.status = //this is the status code ?
o_res.ok = //this is the "OK" from the status line?

i think its a joke to not have access to this information, just because XMLHttpRequest and fetch are API's that doesnt mean that access to such trivial information such as the HTTP response status line cannot be possible... i am glad somebody even asked this question.我认为无法访问此信息是一个笑话,仅仅因为XMLHttpRequestfetch是 API,这并不意味着无法访问诸如 HTTP 响应状态行之类的琐碎信息......我很高兴有人问过这个问题. How should people be able to understand the http request if they dont even have access to the required information如果人们甚至无法访问所需的信息,他们应该如何理解 http 请求

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM