Cara Menggunakan Axios Create dengan Header Authorized
Ya, Axios create dapat mengambil headers authorized. Anda dapat menentukan header authorized dengan cara berikut:
const axios = require('axios');
// Membuat instance Axios dengan header authorized
const instance = axios.create({
headers: {
'Authorization': 'Bearer your-token'
}
});
// Menggunakan instance Axios untuk melakukan request
instance.get('https://example.com/api/endpoint')
.then(response => {
// handle response
})
.catch(error => {
// handle error
});
Dalam contoh di atas, header authorized diatur dengan menggunakan properti headers dalam objek konfigurasi saat membuat instance Axios. Anda dapat mengubah 'Bearer your-token' dengan header authorized yang sesuai dengan kebutuhan Anda.
原文地址: https://www.cveoy.top/t/topic/pg9B 著作权归作者所有。请勿转载和采集!