首页 > 解决方案 > x-www-form-urlencoded api 调用与 axios

问题描述

我正在尝试使用 axios 进行以下 api 调用,但我不确定如何继续。我能够在邮递员中做到这一点,但我对 axios 感到失望,即使它返回 200 OK 状态,它也没有返回我需要的任何数据。

我从我发布的邮递员帖子中获取了所有这些:

import Vue from "vue";
import Vuex from "vuex";
import axios from "./axios-auth.js";

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        username: null,
        password: null,
    },
    actions: {
        login(authData) {
          console.log(authData);
            axios
              .post("/?target=&auth_id=&ap_name=", {
                login: "login",
                username: authData.username,
                password: authData.password,

              },
              {
                headers: {
                  'Content-Type': 'application/x-www-form-urlencoded',
                  'Cache-Control': 'max-age=0',
                  'Origin': 'http://10.000.000.01:8080',
                  'Upgrade-Insecure-Requests': '1',
                  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36',
                  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
                  'Referer': 'http://10.000.000.01:8080/',
                  'Accept-Encoding': 'gzip, deflate',
                  'Accept-Language': 'pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7',
                  'Connection': 'keep-alive',
              }})
              .then(res => {
                console.log(res)
              })
              .catch(error => console.log(error));

          },
    },

});

标签: vue.jsaxios

解决方案


推荐阅读