可以使用JavaScript中的ajax函数或jQuery中的ajax函数来发送http请求,并使用Content-Type头来指定期望的响应格式。
例如,使用ajax函数发送http请求并指定响应格式为JSON:
$.ajax({
url: 'your-url',
method: 'GET',
dataType: 'json', //期望的响应格式为JSON
success: function(response) {
console.log(response);
}
});
或者使用axios库发送http请求并指定响应格式为XML:
axios.get('your-url', {
headers: {'Content-Type': 'text/xml'} //期望的响应格式为XML
})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
});