При использовании Mockapi мой запрос post работает нормально: < /p>
Код: Выделить всё
class User {
user_id = '';
username = '';
email = '';
api_url = 'https://679fe3e324322f8329c4d911.mockapi.io/api/v1';
create() {
let data = {
username: this.username,
email: this.email,
password: this.password
};
data = JSON.stringify(data);
fetch(this.api_url + '/user', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: data
})
.then(response => response.json())
.then(data => {
console.log('User created');
})
.catch(error => console.error(error));
}
}
Код: Выделить всё
class User {
user_id = '';
username = '';
email = '';
api_url = 'http://localhost:1269';
create() {
let data = {
username: this.username,
email: this.email,
password: this.password
};
data = JSON.stringify(data);
fetch(this.api_url + '/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: data
})
.then(response => response.json())
.then(data => {
console.log('User created');
})
.catch(error => console.error(error));
}
}
Код: Выделить всё
POST http://localhost:1269//users 404 (Not Found)
Код: Выделить всё
Uncaught (in promise) SyntaxError: Unexpected token ' Подробнее здесь: [url]https://stackoverflow.com/questions/79443895/using-mockoon-instead-of-mockapi-post-request-not-working[/url]