Я пытаюсь сделать запрос с axios на сервер. Проблема в том, что мой запрос работает нормально с модулем запроса, но не с axios. Мой код выглядит так:
const axios = require('axios');
axios.post('https://mydomain/api/login', {
username: 'test@gmail.com',
password: '123'
})
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});
Ответ от сервера:
{ response: 'Error', error_message: 'Invalid credentials' }
Я делаю тот же запрос с теми же учетными данными, но с модулем запроса, и он работает просто отлично.
var request = require("request");
var options = {
method: 'POST',
url: 'https://mydomain/api/login',
formData: { username: 'test@gmail.com',
password: '123' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
Ответ от сервера:
{"response": "Successfully authenticated.", "email": "test@gmail.com",}
Я что-то упустил?