简体   繁体   English

如何通过使用 axios 发送正文来调用此 get api?

[英]How to call this get api with sending the body using axios?

Hi I can call the the api in the postman like this.嗨,我可以像这样调用邮递员中的 api。

The data return fine in the postman邮递员中的数据返回正常

图片

But when I try to get the api from the axios request the api always give me 500但是当我尝试从 axios 请求中获取 api 时,api 总是给我 500

What am I doing wrong?我究竟做错了什么?

axios
    .get('/dwapi/productsapi/GetProductList', {
      params: {
        group: 'Baby&Kids',
        subgroup: '',
        subsubgroup: '',
        pagesize: '',
        pagenum: '4',
        minprice: '',
        maxprice: '',
        brand: '',
        size: '',
        promotion: '',
        bhgexclusive: '',
        sortorder: '',
        sortby: '',
        search: '',
      },
    })
    .then(res => {
      console.log(res);
      // dispatch({
      //    type: FETCH_PRODUCT_LIST,
      //    payload: res.data,
      // });
    })
    .catch(err => {
      throw err;
    });
axios
    .get('/dwapi/productsapi/GetProductList', {
        group: 'Baby&Kids',
        subgroup: '',
        subsubgroup: '',
        pagesize: '',
        pagenum: '4',
        minprice: '',
        maxprice: '',
        brand: '',
        size: '',
        promotion: '',
        bhgexclusive: '',
        sortorder: '',
        sortby: '',
        search: '',
      }
    )
    .then(res => {
      console.log(res);
      // dispatch({
      //    type: FETCH_PRODUCT_LIST,
      //    payload: res.data,
      // });
    })
    .catch(err => {
      throw err;
    });

It seems like you want to send your parameters in the body and not the URL parameters, thus you should not be specifying the params property:似乎您想在正文中发送参数而不是 URL 参数,因此您不应指定params属性:

axios
    .get('/dwapi/productsapi/GetProductList', {
      group: 'Baby&Kids',
      subgroup: '',
      subsubgroup: '',
      pagesize: '',
      pagenum: '4',
      minprice: '',
      maxprice: '',
      brand: '',
      size: '',
      promotion: '',
      bhgexclusive: '',
      sortorder: '',
      sortby: '',
      search: '',
    })
    .then(res => {
      console.log(res);
      // dispatch({
      //    type: FETCH_PRODUCT_LIST,
      //    payload: res.data,
      // });
    })
    .catch(err => {
      throw err;
    });

In axios, you can try with data instead of params .在 axios 中,您可以尝试使用data而不是params And let me know what will be the result.并让我知道结果是什么。

axios
    .get('/dwapi/productsapi/GetProductList', {
      data: {
        group: 'Baby&Kids',
        subgroup: '',
        subsubgroup: '',
        pagesize: '',
        pagenum: '4',
        minprice: '',
        maxprice: '',
        brand: '',
        size: '',
        promotion: '',
        bhgexclusive: '',
        sortorder: '',
        sortby: '',
        search: '',
      },
    })
    .then(res => {
      console.log(res);
      // dispatch({
      //    type: FETCH_PRODUCT_LIST,
      //    payload: res.data,
      // });
    })
    .catch(err => {
      throw err;
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 axios 参数过滤 API 调用 - How to filter an API Call using axios parameters 如何在 React JS 中使用带和不带参数的 axios 实例编写一个 GET api 调用 - how to write one GET api call using axios instance with and without params in React JS How I get the javascript object I want from the javascript object I have and pass that to a nested (complex) body using Axios to post an API - How I get the javascript object I want from the javascript object I have and pass that to a nested (complex) body using Axios to post an API 在 AXIOS 中为 GET 方法发送请求正文会引发错误 - Sending Request body for GET method in AXIOS throws error 如何在不取消 API 调用的情况下使用 axios 设置超时? - How to set a timeout using axios without cancelling API call? 如何使用API​​调用中的axios在React中使用异步等待 - How to use async await in React using the axios in the API call 我不知道如何使用 axios.get() 调用来使用硬币壁虎 API 获取加密货币的价格 - I can't figure how to use the axios.get() call to get the prices of cryptocurrencies using the coin gecko API 如何从axios API调用获取响应的ID —使用React Native的Axios - how to get the id of a response from an axios API call — Axios with React Native 在axios中发送带有正文的POST请求 - Sending POST request with body in axios 如何在 Nativescript 应用程序中调用 axios/api - How to call axios/api call in Nativescript application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM