无法使用axios发送带头的get请求

时间:2017-11-05 11:12:48

标签: javascript api react-native axios

能够在postman中获得回复。但无法进入axios。获取html作为响应。会出现什么问题?

import axios from 'react-native-axios';

var config = {
  headers: {
    'Content-Type': 'Application/Json',
    'JsonStub-User-Key': '__USER__KEY',
    'JsonStub-Project-Key': '__PROJECT__KEY'
  }
};

export async function menuListByCategories() {
  // simulate an asynchronous operation
  const url = "http://jsonstub.com/burgers";
  axios.get(url, {config})
    .then((response) = > {
      console.log(response.data);
    })
    .
  catch ((error) = > {
    console.log("axios error:", error);
  });
}

更新: check the response of this code

1 个答案:

答案 0 :(得分:1)

您可以在data: {}中添加config,以免被axios删除Content-Type。检查下面问题的答案。

Jsonstub response not showing