【问题标题】:Getting error 404 when use basic auth使用基本身份验证时出现错误 404
【发布时间】:2023-03-08 10:45:01
【问题描述】:

我正在尝试使用 Fetch 进行 GET 查询,但在通过授权时收到错误 404。
我不知道为什么会出现这个错误,因为我使用 Postman 之类的工具时服务器响应良好。

Authorization: Basic ...
method: GET
url: https://zammad.zonngo.com/api/v1/ticket_articles

当我使用Javascript fetch API 时,会出现错误 404。

OPTIONS https://zammad.zonngo.com/api/v1/ticket_articles 404 (Not Found)

这是我的代码:

const myHeaders = new Headers();
myHeaders.append('Authorization','Basic ...');
myHeaders.append('Content-Type','application/json');
fetch(URLTICKETS, {
  method: 'GET',
  headers: myHeaders
})
.then(response => {
  console.log(response);
})
.then(error => {
  console.log(error);
});

如果有人可以帮助我,那就太好了。

【问题讨论】:

    标签: javascript ajax http-headers authorization fetch-api


    【解决方案1】:

    URL 上的GET 方法返回401 状态码OPTIONS 方法实际上返回404。

     http OPTIONS https://zammad.zonngo.com/api/v1/ticket_articles
     HTTP/1.1 404 Not Found
     Connection: keep-alive
     Content-Encoding: gzip
     Content-Type: text/html; charset=UTF-8
     Date: Thu, 02 Nov 2017 01:37:59 GMT
     Server: nginx/1.10.3 (Ubuntu)
     Transfer-Encoding: chunked
     X-Request-Id: 16f58319-2658-4b0e-824c-08ca68e8d401
     X-Runtime: 0.003135
    

    OPTIONS 可能是由 CORS 预检请求引起的,https://zammad.zonngo.com/ 似乎没有正确处理该请求。

    https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-19
      • 2013-12-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多