浏览器的地址栏只支持GET请求,无法直接用POST请求。要使用POST请求,需要在页面中使用表单或JavaScript等方式发送POST请求。例如,在JavaScript中可以使用XMLHttpRequest对象发送POST请求,如下所示:

var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://example.com/api', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function() {
  if (xhr.readyState === 4 && xhr.status === 200) {
    console.log(xhr.responseText);
  }
};
xhr.send(JSON.stringify({username: 'abc', password: '123'}));

这段代码使用XMLHttpRequest对象发送一个POST请求到http://example.com/api,请求的内容为JSON格式的{username: 'abc', password: '123'}。在发送之前,需要设置请求头的Content-Type为application/json,以告诉服务器请求的内容类型。发送完成后,在onreadystatechange事件回调函数中可以获取服务器返回的响应内容

在浏览器的地址栏怎么用post请求

原文地址: https://www.cveoy.top/t/topic/fVcl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录