如何使用服务器401响应中的标头

问题描述

服务器正在使用摘要身份验证方法,我发出请求并获得401响应,在WWW-Authenticate字段的随机数中,我得到了执行第二个身份验证请求所需的内容,但无法将其提取以工作。

async function doRequest() {
    let response = await fetch('URL',{
        method: 'GET',mode: 'no-cors',headers: {
            Accept: '*/*',},})

    alert(response.headers.get('Content-Type'));
}  

如何操作这些标题

解决方法

尝试这样的事情:

async function doRequest() {
    let response = await fetch('URL',{
        method: 'GET',mode: 'no-cors',headers: {
            Accept: '*/*',},})
return response;
}

doRequest()
  .then(response => alert(response.headers.get('Content-Type')););