查看默认的请求头
import axios from 'axios' let url = 'http://httpbin.org/get' const res = await axios.get(url) console.log(res.data); // 'User-Agent': 'axios/0.27.2',
设置一个请求头
import axios from 'axios' let url = 'http://httpbin.org/get' const headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36', } const res = await axios.get(url, { headers, }) console.log(res.data) // 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'