axios请求post变成get同时多一个别的地址的options请求

配置请求头和请求拦截后,试验获取token值,但是post请求会变成get请求,同时多了一个http://www.139site.com/?e=dns&t=api.mars.net/router/token.htm的请求,config中跨域请求也配置好了,就是请求不出来,试过别的地址请求可以做到,就是想不通了

import Qs from "qs";
import _vue from "@/main.js";
import axios from "axios";
import store from "@/store/index";

axios.defaults.headers["Content-Type"] = "application/x-www-form-urlencoded";
axios.defaults.headers["X-Requested-With"] = "XMLHttpRequest";
axios.defaults.withCredentials = true;
axios.defaults.crossDomain = true;

/**
 * 请求拦截器
 */
axios.interceptors.request.use(
  config => {
    let token = window.sessionStorage.getItem("x_token");
    config.data.x_token = token;
    config.data = Qs.stringify(config.data);
    return config;
  },
  err => {
    return Promise.reject(err);
  }
);
let baseUrls = baseUrl + "/token.htm";
// 获取 token
const getToken = () => {
  // 清空 token
  window.sessionStorage.setItem("x_token", "");
  axios
    .post(baseUrls, {})
    .then(res => {
      if (res.success) {
        store.commit({
          type: "getToken",
          x_token: res.data.x_token
        });
      } else {
        getToken();
      }
    })
    .catch(res => {
      console.log(res);
    });
};

报错:
Access to XMLHttpRequest at 'http://www.139site.com/?e=dns&t=api.mars.net/router/token.htm' (redirected from 'http://console.mars.net:81/baseUrl/token.htm') from origin 'http://console.mars.net:81' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐