Axios API 請求
Node.js Axios API 請求
Categories:
安裝
npm install axios
yarn add axios
Axios 跨網域 CORS 請求
前端框架
import axios from 'axios';
let data = {
key: 'value'
};
try {
let response = await axios.post('https://localhost:3000/api', data, {
httpsAgent: {
rejectUnauthorized: false
},
validateStatus: function (status) {
return true; // always resolve
}
});
console.log(response.data);
} catch (error) {
console.log(error);
}
Node.js
import axios from 'axios';
import https from 'https';
let data = {
key: 'value'
};
try {
let response = await axios.post('https://localhost:3000/api', data, {
httpsAgent: new https.Agent({
rejectUnauthorized: false
}),
validateStatus: function (status) {
return true; // always resolve
}
});
console.log(response.data);
} catch (error) {
console.log(error);
}