chrome控制台发送post请求

chrome控制台发送post请求

chrome控制台发送post请求chrome, 按F12,打开控制台, 执行下面脚本

代码

var url = "https://www.test.com/Admin/testpost;

var params = {id:"1",name:"q"};

var xhr = new XMLHttpRequest();

xhr.open("POST", url, true);

xhr.setRequestHeader("Content-Type", "application/json");

xhr.onload = function (e) {

if (xhr.readyState === 4) {

if (xhr.status === 200) {

console.log(xhr.responseText);

} else {

console.error(xhr.statusText);

}

}

};

xhr.onerror = function (e) {

console.error(xhr.statusText);

};

xhr.send(JSON.stringify(params));

补充:

也可直接在chrome页面按下Ctrl+shif+J ,在网络中刷新页面,在相应的请求上,复制 fetch格式,即可用来在console中发送POST请求

对于POST请求返回的是readablestream的,可用以下代码显示在console中:

fetch('https://jsonplaceholder.typicode.com/posts/1')

.then(function(response) {

// The response is a Response instance.

// You parse the data into a useable format using `.json()`

return response.json();

}).then(function(data) {

// `data` is the parsed version of the JSON returned from the above endpoint.

console.log(data); // { "userId": 1, "id": 1, "title": "...", "body": "..." }

});

参考:

https://stackoverflow.com/questions/40385133/retrieve-data-from-a-readablestream-object

https://www.cnblogs.com/barrysgy/p/15696559.html

相关推荐

带琳字的女孩名字大全
365bet网站是多少

带琳字的女孩名字大全

📅 01-28 👁️ 1725
乐高太贵?10个品牌积木玩具购买指南请收好
S365网络超时

乐高太贵?10个品牌积木玩具购买指南请收好

📅 06-14 👁️ 5992
三国谋事郭图是怎样的人?他是被曹操杀死的吗
365bet娱乐官

三国谋事郭图是怎样的人?他是被曹操杀死的吗

📅 02-02 👁️ 7026