score:5
Accepted answer
This is happening because Axios serializes JavaScript objects to JSON. To serialize in application/x-www-form-urlencoded format you will need to use one of the techniques described in the Axios documentation.
I think qs is a nice solution for you:
let apiUrl = 'http://localhost:3001/api/teams';
//sends the id and new author/text to our api
axios.put(`${apiUrl}/${id}`, qs.stringify(player)).catch(err => {
console.log(err);
});
score:1
Axios doesn't like posting plain objects.
One way to workaround issue is with FormData
:
let formData = new FormData();
formData.append('param1', 'hi');
formData.append('param2', 'hello');
axios({
method: 'POST',
url: '/api/some-endpoint/',
data: formData
}).then(response => {
console.log(response);
});
Source: stackoverflow.com
Related Query
- Put works in Postman but not AXIOS
- Sending a post request through Axios is generating an empty RequestBody in Spring-Boot backend. Works in Postman but not through Axios post request
- Starting a php session from react with an axios call does not keep the session alive, but doing it with postman works just fine
- How can I properly add headers in my axios post request, post route works in postman but not when using axios
- PUT method is not working in front end but works in Postman
- Request made with axios does not work but if it works with XMLHttpRequest
- Axios not updating state from API in function called on Click, but works on identical function on Component Mount in React
- Auth error with POST request: "Authentication credentials were not provided" using Axios, but works using POSTMAN
- IFormFile in .NET Core Web API is null for axios and ajax file upload but works in Postman
- Token in LocalStorage is there but not being put inside my Axios Instance
- Axios headers work for Django GET request, but not PUT request
- Spring Boot Security module gives 403 error when called by using axios from react but works fine in postman
- Ruby on Rails does not include Authorization token on header when request by axios in React, but it does work with Postman
- Authorization request works in Postman but not in React
- passport authentication works from postman but not with fetch()
- Postman works but not react redux action (axios.post request)
- React JS + React Router works with $.get but not $.ajax PUT
- File Upload Error - Works in Postman but not on frontend
- request works with Postman but not with axios.post
- Axios post fails with 403 error code and showing CSRF token validation failed but works fine django api when passing csrftoken in header with Postman
- React - WP_Mail works with jQuery but not axios
- my express api works in postman but not when calling from react.It gives "TypeError: NetworkError when attempting to fetch resource."
- React: I have a try/catch block in a service that I'm trying to add an Axios call to but I'm not sure where to put it
- File Upload to BIM 360 works in Postman but not with React JS
- POST request to API created by lambda function in amazon AWS in python works good in postman but not in reactjs code
- Axios (React) get request returns 403 from firebase, but works on postman
- How come in Postman my post request works but not in the browser even though I'm doing the same?
- Upload File Api request works in postman but not in nodejs and react MERN
- Axios get in url works but with second parameter as object it doesn't
- React Routing works in local machine but not Heroku
More Query from same tag
- Where should react-thunk func go if no componentWillReceiveProps?
- React - "TypeError: undefined is not a function (near '...formFields.map...')"
- How to reformat a JSON array into another format "grouping" based on different keys
- How to save Redux Store as a downloaded file and then load it back?
- Why my methods for React function components don't work
- Returning a callback from useEffect
- Cannot get redux state inside the provider file
- Reduce duplicate codes on switch case on React prop value improve code resuability
- React - Dynamic form fields where fields change based on a dropdown menu (using hooks)
- Expected an assignment or function call and instead saw an expression @typescript-eslint/no-unused-expressions (React)
- GET {url localhost } net::ERR_SSL_PROTOCOL_ERROR problem with my custom api
- Typescript Getting Child Props in Props
- How to change State immutably React
- React-Leaflet change GEOJSON shape color by state change
- I cannot change the array in State
- How can I add live-reload to my nodejs server
- React webpack create bundle with separated react
- How to unit test a component under React Router 4
- React-router with TypeScript, match parameters are always undefined
- Unit test: simulate the click event of child component in parent using enzyme
- Rendering three components in pairs in React
- Getting html tag into data from API post method
- How do I clear states or empty array on click in react 0.14 ES6?
- Ability to enter tab characters in a TextField?
- Simple selector and nested selector in JSS
- When is it appropriate to use a constructor in REACT?
- What is the best way to trigger an redux action if the props changed after the react 16.3?
- Receiving "Attempted import error:" in react app
- React-Modal-Image displaying off center image when clicked
- How to encapsulate useState of components in react?