HttpRequest::getRequestHeaders 似乎只是 return headers 的一个子集?
HttpRequest::getRequestHeaders only seems to return a subset of headers?
如您所见,我提出了一个成功的请求。我遇到的问题是我在下面打印出来的第 3 行。
var headerList = request.getAllResponseHeaders();
print("RunTime type of Header List: ${headerList.runtimeType}");
print("Header List Count: ${headerList.length}");
print("Header List is as follows: \n$headerList");
看来 HttpRequest
请求的信息 return 不够。我希望它 return 可以是所有 header 信息的完整字符串、k=>v 对的映射或数组。
好像只获取了前 64 个字符。
为什么它不能获取所有文件?理想情况下,我试图通过 request.getResponseHeader("Content-Disposition");
获取 "Content-Disposition" header,但正如您可以想象的那样,鉴于此信息,它实际上将 return 为空,因为请求找不到该信息。
我猜你需要添加
Access-Control-Expose-Headers
Content-Disposition
在您的服务器上。
Access-Control-Expose-Headers
(optional) - The XMLHttpRequest 2 object
has a getResponseHeader()
method that returns the value of a
particular response header. During a CORS request, the
getResponseHeader()
method can only access simple response headers.
Simple response headers are defined as follows:
- Cache-Control
- Content-Language
- Content-Type
- Expires
- Last-Modified
- Pragma
If you want clients to be able to access other headers, you
have to use the Access-Control-Expose-Headers
header. The value of
this header is a comma-delimited list of response headers you want to
expose to the client.
如您所见,我提出了一个成功的请求。我遇到的问题是我在下面打印出来的第 3 行。
var headerList = request.getAllResponseHeaders();
print("RunTime type of Header List: ${headerList.runtimeType}");
print("Header List Count: ${headerList.length}");
print("Header List is as follows: \n$headerList");
看来 HttpRequest
请求的信息 return 不够。我希望它 return 可以是所有 header 信息的完整字符串、k=>v 对的映射或数组。
好像只获取了前 64 个字符。
为什么它不能获取所有文件?理想情况下,我试图通过 request.getResponseHeader("Content-Disposition");
获取 "Content-Disposition" header,但正如您可以想象的那样,鉴于此信息,它实际上将 return 为空,因为请求找不到该信息。
我猜你需要添加
Access-Control-Expose-Headers
Content-Disposition
在您的服务器上。
Access-Control-Expose-Headers
(optional) - The XMLHttpRequest 2 object has agetResponseHeader()
method that returns the value of a particular response header. During a CORS request, thegetResponseHeader()
method can only access simple response headers. Simple response headers are defined as follows:
- Cache-Control
- Content-Language
- Content-Type
- Expires
- Last-Modified
- Pragma
If you want clients to be able to access other headers, you have to use the
Access-Control-Expose-Headers
header. The value of this header is a comma-delimited list of response headers you want to expose to the client.