摘要式身份验证HTTP GET请求(Javasctipt)

时间:2020-09-22 12:32:34

标签: javascript get http-status-code-401

我正在尝试向连接到需要摘要式身份验证的本地网络的设备发出HTTP GET请求,我已经编写了此请求,但是当我单击浏览器控制台中的按钮时,它返回“ 401未经授权” 您的客户端没有权限从该服务器获取URL。”我在google中搜索了很多内容,发现出现此错误是因为设备具有摘要式身份验证,问题是如何在不返回401错误的情况下发出请求并运行请求没有错误。(我知道设备的用户名和密码)。

<!DOCTYPE html>
<html>
<head>
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<button onclick="call();">Make a request</button>
</body>

<script>
    function call()
    {
        var url = "http://myurl.com";
        
        var xhr = new XMLHttpRequest();
        xhr.open("GET", url);
        
        xhr.onreadystatechange = function () {
           if (xhr.readyState === 4) {
              console.log(xhr.status);
              console.log(xhr.responseText);
           }};
        
        xhr.send();     
    }
    </script>


</html>

0 个答案:

没有答案