javascript - Set header using in React (ajax) - Stack Overflow

try set header, in Ajax Request using axios import React, { Component, PropTypes } from 'react

try set header, in Ajax Request using axios

import React, { Component, PropTypes } from 'react'
import { Link, browserHistory } from 'react-router'
import { connect } from 'react-redux'
import axios from 'axios'

class Ine extends Component {
  constructor(props) {
    super(props)

     this.state = {     
        };


  }


ponentDidMount() {


 axios.post('http://139.196.141.166:8084/course/ine/outline', {
      headers: { 'X-Authenticated-Userid': '15000500000@1' }
    })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
    }





render() {

        return (
            <div>
                dsdss
            </div>
        )
    }

But server returns me, that I not setup header. I setup it like in documentation, but header is not set.

There screen with error

try set header, in Ajax Request using axios

import React, { Component, PropTypes } from 'react'
import { Link, browserHistory } from 'react-router'
import { connect } from 'react-redux'
import axios from 'axios'

class Ine extends Component {
  constructor(props) {
    super(props)

     this.state = {     
        };


  }


ponentDidMount() {


 axios.post('http://139.196.141.166:8084/course/ine/outline', {
      headers: { 'X-Authenticated-Userid': '15000500000@1' }
    })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
    }





render() {

        return (
            <div>
                dsdss
            </div>
        )
    }

But server returns me, that I not setup header. I setup it like in documentation, but header is not set.

There screen with error

Share Improve this question asked Jan 22, 2017 at 12:25 Егор КротенкоЕгор Кротенко 8183 gold badges14 silver badges35 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

From what I can see, the method call looks like this (from docs):

axios#post(url[, data[, config]])

As you are posting your config object as second argument, its interpreted as data, not as config (headers is part of the config object)


Edit: Here is an example:

axios.request({
  url: 'http://139.196.141.166:8084/course/ine/outline',
  method: 'post',
  headers: { 'X-Authenticated-Userid': '15000500000@1' }
})

Note that i switched over from .post() to .request() which only takes a config object. If you still want to use the .post() call, try:

axios.post(url, {}, { headers: ... })

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743965931a4537538.html

相关推荐

  • javascript - Set header using in React (ajax) - Stack Overflow

    try set header, in Ajax Request using axios import React, { Component, PropTypes } from 'react

    2天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信