错误:请求失败,状态码为400

时间:2020-09-14 18:57:40

标签: reactjs axios jwt

我收到400请求失败,状态码为400错误。有人知道我在做什么错吗?我有正确的JWT。以下是我的App.js文件和console.log中的错误代码段。预先非常感谢。

import React, { useState, useEffect } from 'react';
import './App.css';
import Axios from 'axios';
import Styled from 'styled-components';

const  Wrapper = Styled.div `
  padding: 2%;
  margin: 2%;
  border: 1px solid dodgerblue;
`;

function App() {
  const [clanData, setClanData] = useState([]);
  const jwt = "<MY API TOKEN HERE>";
  const clanTag = "%23LPPLR8YL";
  const clanUrl = `https://cors-anywhere.herokuapp.com/https://api.clashroyale.com/v1/clans/${ clanTag }`;

  useEffect(() => {
    Axios
      .get(clanUrl, {
        headers:
        { authorization: `Bearer ${ jwt }`, 'Content-Type': 'application/json' }
      })
      .then((res) => {
        console.log(res.data);
        setClanData(res.data);
      })
      .catch((err) => {
        console.log(err);
      });
  }, [clanData]);
  return (
    <Wrapper>
      Still Not A Pro
    </Wrapper>
  );
}

export default App;

https://i.stack.imgur.com/ppPHZ.png

0 个答案:

没有答案