首页 > 解决方案 > 如何通过 vuejs 中的获取请求传递凭据?

问题描述

我试图通过这样的凭据:

fetch(this.url + '/auth/login', {method:'GET', 
  headers: {'Authorization': 'Basic ' + btoa('xxxx:xxxx')}})
  .then(response => response.json())
  .then(json => console.log(json));

但它在控制台中给出了这个错误:

GET https://stagingapi.pikflick.com/auth/login 404 (Not Found)

我尝试了另一种方式:

fetch(this.url + "/auth/login", {
      method: 'GET',
      credentials: 'include',
      redirect: 'follow',
      agent: null,
      headers: {
          "Content-Type": "text/plain",
          'Authorization': 'Basic ' + btoa('xxxx:xxxx'),
      }
  });

它显示了这个错误:

CORS 策略已阻止从源“http://localhost:8080”访问“https://stagingapi.pikflick.com/auth/login”获取

谁能告诉我如何通过凭据?我第一次使用招摇。任何人都可以帮忙。我将不胜感激。

标签: swagger-uifetch-api

解决方案


推荐阅读