有没有一种方法,使一个HTTP请求使用Chrome开发工具,而不使用插件像海报?


当前回答

如果你在你的网站上使用jquery,你可以在你的控制台上使用这样的东西

$ . post ( “dom / data-home.php”, { 类型:"home", id: "0" }、功能(数据){ console.log(数据) }) < script src = " https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js " > < /脚本>

其他回答

如果你的网页有jquery在你的页面,那么你可以做它写在chrome开发者控制台:

$.get(
    "somepage.php",
    {paramOne : 1, paramX : 'abc'},
    function(data) {
       alert('page content: ' + data);
    }
);

这是jquery的方法!

我知道,老帖子……但把这个留在这里可能会有帮助。

现代浏览器现在支持Fetch API。

你可以这样使用它:

fetch("<url>")
    .then(data => data.json()) // could be .text() or .blob() depending on the data you are expecting
    .then(console.log); // print your data

ps:它将进行所有的CORS检查,因为它是一个改进的XmlHttpRequest。

要GET带报头的请求,请使用此格式。

   fetch('http://example.com', {
      method: 'GET',
      headers: new Headers({
               'Content-Type': 'application/json',
               'someheader': 'headervalue'
               })
    })
    .then(res => res.json())
    .then(console.log)

$ . post ( “dom / data-home.php”, { 类型:"home", id: "0" }、功能(数据){ console.log(数据) }) < script src = " https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js " > < /脚本>

扩展@dhfsk答案

这是我的工作流程

在Chrome DevTools中,右键单击您想要操作> Copy作为cURL的请求 开放的邮递员 单击左上角的导入,然后粘贴原始文本