如何通过以下代码使用AXIOS提出请求

发布于 2025-02-13 22:14:00 字数 373 浏览 0 评论 0原文

我面对,拒绝设置不安全的标题“用户代理”问题,同时尝试使用WooCommerce REST API V3提出请求。我想通过使用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: {},
  },
})

I faced, Refused to set unsafe header "User-Agent" issue while trying to make get request using woocommerce rest api v3. I want to make get request by using axios modifying the header. So How to do this using this code below from 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: {},
  },
})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

汹涌人海 2025-02-20 22:14:06

尝试将“ content-type”添加:“ application/json; charset = utf-8” so:

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

Try adding "Content-Type": "application/json;charset=UTF-8" to the headers like so:

const api = new WooCommerceRestApi({
    url: url,
    consumerKey: consumerKey,
    consumerSecret: consumerSecret,
    version: "wc/v3",
    axiosConfig:{
      headers:{
        "Content-Type": "application/json;charset=UTF-8"
        }
    }
  });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文