I am making a very simple POST
request with axios
in an expressjs
app like so:
const try = async () => {
const axios = require('axios');
const output = { url: "www.example.com"}
await axios.post(`http://localhost:3000/myapp`, output)
// do something else
}
The above requests works. However, when I change output
to :
const output = {
url:{
test: "www.example.com"
}
}
The post request throws:
Error: Request failed with status code 500
at createError (/node_modules/axios/lib/core/createError.js:16:15)
at settle (node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (node_modules/axios/lib/adapters/http.js:322:11)
at IncomingMessage.emit (node:events:339:22)
at IncomingMessage.EventEmitter.emit (node:domain:548:15)
at endReadableNT (node:internal/streams/readable:1289:12)
at processTicksAndRejections (node:internal/process/task_queues:80:21)
Why is there a problem with a nested Object but not a flattened one?
CodePudding user response:
The request is sending data to a nosql
management system which is setting certain default data types on first sending the request.
Sending the request again with different data types will cause an error. The issue was resolved by making sure data sent to the dbms was consistent.
If sending javascript
objects whether they are stringified or not makes a difference.
CodePudding user response:
In this request you Send Two url at same time in axios. I think this error because this.