javascript - 无法使用 axios 发送带 header 的 get 请求

标签 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

最佳答案

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

Jsonstub response not showing

关于javascript - 无法使用 axios 发送带 header 的 get 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47120899/

相关文章:

api - 如何安静地暴露相关的父子资源?

javascript - 参数中带有 getter 的 AngularJS 资源

react-native - 如何在react-native中向Date()添加分钟?

javascript - 如何处理多个复选框

javascript - 查找 .CSV 中的唯一值

javascript - HTML 打开弹出窗口,无需用户点击

api - 如何从 UPS Rate API 获取费率?

javascript - React Native 数据不会在第一次点击时推送到 firebase

javascript - 查询多个Youtube channel

javascript - 如何确保 hibernate 版本号在 javascript 客户端中保持不可变?