【问题标题】:How to make get request using axios by the following code如何通过以下代码使用 axios 发出请求
【发布时间】:2022-10-02 20:09:15
【问题描述】:

我在尝试使用 woocommerce rest api v3 发出获取请求时遇到了拒绝设置不安全的标头“User-Agent”问题。我想通过使用 axios 修改标头来发出获取请求。那么如何使用下面来自 axios 的代码来做到这一点?

const woocommerce = new WooCommerceRestApi({
  url: process.env.REACT_APP_WP_URL,
  consumerKey: process.env.REACT_APP_WP_KEY,
  consumerSecret: process.env.REACT_APP_WP_SECRET,
  version: \'wc/v3\',
  axiosConfig: {
    headers: {},
  },
})

    标签: reactjs axios wordpress-rest-api


    【解决方案1】:

    尝试将"Content-Type": "application/json;charset=UTF-8" 添加到标题中,如下所示:

    const api = new WooCommerceRestApi({
        url: url,
        consumerKey: consumerKey,
        consumerSecret: consumerSecret,
        version: "wc/v3",
        axiosConfig:{
          headers:{
            "Content-Type": "application/json;charset=UTF-8"
            }
        }
      });
    

    【讨论】:

      猜你喜欢
      • 2019-10-26
      • 2018-04-25
      • 2021-06-30
      • 1970-01-01
      • 2022-11-02
      • 2021-09-20
      • 1970-01-01
      • 2011-08-29
      • 1970-01-01
      相关资源
      最近更新 更多