If I make a post to the server the browser's developer console throw it away that: 'http-client.js:28 POST http://todoapp.test/api/create 500 (Internal Server Error)', but if I send it to the same url with POSTMAN, the server save the data.
Here is my POST function:
export class HttpClient { constructor(url) { this.url = url; this.xhr = new XMLHttpRequest(); this.xhr.onloadend = (event) => { return this.xhr.response; } } setHeader(header) { this.xhr.setRequestHeader(header.name, header.value); } post(async, data, header) { return new Promise((resolve, reject) => { this.xhr.open('POST', this.url + 'create', async); this.xhr.setRequestHeader(header.name, header.value); this.xhr.send(data); resolve(this.xhr.response); }); }
Where is the problem on the server or on my code? And how can I fix that?
I think you should set contentType: "application/json" might be help please try this
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.