Olá, estou tentando pegar o get de uma api com axius usando react, so que me retorna o error {"error":{"message":"Missing
Content-Type: application/jsonheader"}}
Code:
import React, { Component } from ‘react’ import axios from ‘axios’
import PageHeader from ‘../template/pageHeader’ import TodoForm from ‘./todoForm’ import TodoList from ‘./todoList’
const URL = ‘xxx’
const config = { responseType: ‘json’, headers: { ‘Accept’: ‘application/json’, ‘Content-Type’: ‘application/json’ }, }
export default class Todo extends Component {
constructor(props) { super(props) this.state = { description: '' , list: [] } this.handleChange = this.handleChange.bind(this) this.handleAdd = this.handleAdd.bind(this) } handleChange(e) { this.setState({...this.state, description: e.target.value}) } handleAdd() { axios.get(`xxx` , config).then(resp => { console.log(resp) }) // const description = this.state.description // axios.get(URL, {headers: {'Content-Type': 'application/json' ,} } ).then( // resp => console.log('Funcionou')) // console.log(this.state.description) } render() { return ( <div> <PageHeader name='Tarefas' small='Cadastro' /> <TodoForm description={this.state.description} handleAdd={this.handleAdd} handleChange={this.handleChange}/> <TodoList /> </div> ) }
}