axios网络请求的请求头
时间: 2023-09-29 16:04:02 浏览: 138
axios网络请求的请求头可以通过设置axios.defaults.headers来实现。在代码中,我们可以使用以下语句设置请求头:
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'
或者可以在请求的config对象中设置headers属性,如下所示:
config.headers = { 'X-Requested-With': 'XMLHttpRequest' }
这样设置请求头可以帮助我们在网络请求中传递特定的信息,比如判断是否是XMLHttpRequest请求等。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [详解Vue-axios 设置请求头问题](https://download.csdn.net/download/weixin_38607026/12948952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [axios设置请求头](https://blog.csdn.net/web18224617243/article/details/126098794)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文