浏览器是使用get请求吗怎么改为post
浏览器可以使用get和post两种请求方式。
如果需要将请求方式从get改为post,可以在发送请求时将请求方法设置为post,例如:
var xhr = new XMLHttpRequest();
xhr.open('POST', 'url', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.send('data');
其中,xhr.open('POST', 'url', true)将请求方法设置为post;xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')设置请求头;xhr.send('data')发送请求体。
需要注意的是,如果是通过表单提交数据,可以直接将form的method属性设置为post即可。
原文地址: https://www.cveoy.top/t/topic/fVbp 著作权归作者所有。请勿转载和采集!