Network Error making post request using Axios

Tm Son

I'm trying to make my application sending a post request and receiving a response using Axios. However i encoutered errors while trying to make a post request.

My code for making post request:

onPostJson = () => {
  axios.post('https://10.1.127.17:11111/vpdu/get-ca-thu-hoi',
  {
    FromDate: "01-Jan-2020",
    ToDate: "01-Feb-2020",
    Ca: 1
  })
  .then((response) => {
    console.log(response.json());
  }, (error) => {
    console.log(error);
  });
};

Error:

Network Error
- node_modules\axios\lib\core\createError.js:15:17 in createError
- node_modules\axios\lib\adapters\xhr.js:80:22 in handleError
- node_modules\event-target-shim\dist\event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:574:29 in setReadyState
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:388:25 in __didCompleteResponse
- node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:190:12 in emit
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:436:47 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17 in __guard$argument_0
* [native code]:null in callFunctionReturnFlushedQueue

I suspected that there is problem with the URL, but i successfully made a post request to this URL using Postman.

Solution: It was syntax error. I forgot to include Header configurations in the code.

onPostJson = () => {
      console.log("onpost");
      axios.post('http://10.1.127.17:11111/vpdu/get-ca-thu-hoi', {
        FromDate: "01-Jan-2020",
        ToDate: "01-May-2020",
      }, {
            headers: {
                'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6ImtpZW50ZC5haXRzIiwibmJmIjoxNTkzNzY0MDU0LCJleHAiOjE1OTQzNjg4NTQsImlhdCI6MTU5Mzc2NDA1NH0.liIM6g2E_EMXvnRpL1RcU-QVyUAKYxVLZZK05OqZ8Ck',
                'Content-Type': 'application/json',
                Accept: 'application/json',
            },
        })
        .then(respond => {
          // console.log(respond.data.CaThuHoiList);
          setShiftData(respond.data.CaThuHoiList);
        })
        .catch(function (error) {
          console.log('Error');
          console.log(error);
        });
    }
luyoes
axios.post('https://10.1.127.17:11111/vpdu/get-ca-thu-hoi', {
        headers: {
            'Content-Type': 'application/json',
            Accept: 'application/json',
        },
          FromDate: "01-Jan-2020",
          ToDate: "01-Feb-2020",
          Ca: 1
    });

i'm not sure, but ..

Do you want to try it like the code above?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Post request Axios : Network error

Vuejs axios error when making post request

Network error on posting a request using axios

Axios not making request, no result, no error

React native axios post request network error on Android physical device

Axios network error even though the post request returns 200

Making POST to DRF using Axios

Axios: Network Error and not sending request

Internal Server Error when making POST request using Rest Assured

Making post request using urllib

making POST request using fetch

Error 400 when making POST request to Spotify API with Axios on Express.js

React Query error when making axios request

request(...).then is not a function error when making a POST request

Axios multiple request on get and post request error

Axios and fetch both in Reactjs are making continuous localhost network request

Making a delete request using Axios to Laravel API throws an error but works fine in insomnia

Making a POST request using urllib with multiple headers gives 400 Bad Request error

Making Simple Post Request With Axios, React.js and Spring

Axios making double post request while loading page

CORS error while making post request to logstash

Error in making POST request to django API

Making a POST request using puppeteer with JSON payload

Making a post request to server using angular

axios post request to MongoDB Atlas error 11000

Axios post request is returning 401 unauthorised error

post request by axios to laravel giving 500 error

Error in Axios API Post request in Nodejs

405 error making axios put/patch request from vue to laravel