Javascript firebug:如何在 firebug 控制台中发送 POST 数据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11589726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 06:26:53  来源:igfitidea点击:

firebug: how to send POST data in firebug console?

javascripthtmlfirebug

提问by Bin Chen

Is it possible to send data to the server using POST?

是否可以使用 POST 将数据发送到服务器?

Ie) I want to send POST data to url:

即)我想将 POST 数据发送到 url:

http://www.a.com/b?cmd=tt

With POST data:

使用 POST 数据:

a=1
b=2

Is it doable and how?

它可行吗?

采纳答案by jeff

Quote from Mike Cooper on a similar question:

引用 Mike Cooper 的类似问题:

As far as I know, Firebug can't do this. However, there is a very useful Firefox extension, in the spirit of Firebug, called Tamper Data. This should be able to do what you want.

It allows you to monitor each request made by the browser, and you can turn on an option that allows you to look at, and edit, every single request before it gets sent.

据我所知,Firebug 不能这样做。但是,本着 Firebug 的精神,有一个非常有用的 Firefox 扩展,称为Tamper Data。这应该能够做你想做的。

它允许您监视浏览器发出的每个请求,并且您可以打开一个选项,允许您在发送之前查看和编辑每个请求。

See other answers at source: How do I POST to a web page using Firebug?
Also see: Using Firebug to send form data

在源代码中查看其他答案: How do I POST to a web page using Firebug?
另请参阅:使用 Firebug 发送表单数据



The above work if you simply want to modify HTTP requests, but to actually create HTTP requests, there is a Firefox extension called Poster, which has the following description:

上面的工作如果你只是想修改 HTTP 请求,但要真正创建 HTTP 请求,有一个名为Poster的 Firefox 扩展,其描述如下:

A developer tool for interacting with web services and other web resources that lets you make HTTP requests, set the entity body, and content type. This allows you to interact with web services and inspect the results...

用于与 Web 服务和其他 Web 资源交互的开发人员工具,可让您发出 HTTP 请求、设置实体主体和内容类型。这允许您与 Web 服务交互并检查结果...

回答by jakub.g

In fact, you can now (since Firefox 3.5) make pure XHRPOST from Firebug, to any domain, you just like in pure JavaScript on the page, with the subject of the same restrictions.

事实上,您现在(自 Firefox 3.5 起)可以从 Firebug 向任何域进行纯XHRPOST,您就像在页面上使用纯 JavaScript 一样,具有相同的主题限制。

The code is a bit lengthy and not handy at all though if you want to use it frequently (unless you store it and copy-paste each time)

代码有点冗长而且根本不方便,但如果你想经常使用它(除非你每次都存储它并复制粘贴)

Paste into console (it would open Command Editor automatically, as it's > 1 line)

粘贴到控制台(它会自动打开命令编辑器,因为它 > 1 行)

var xhr = new XMLHttpRequest();
xhr.open("POST", "http://test/xhrtest.php?w=www");
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send("a=aaa&b=bbb");

Remember that on server-side, you must enable CORS, to see the response in Firebug (otherwise, the request will be sent, but you won't see the response in Firebug; you could see it in Fiddlerthough); if you opened Firebug while you're on page http://foo/somepage, then that URL will be sent by XHR in the HTTP referrer header field, and that domain must be allowed to receive XHR responses via Access-Control-Allow-Originheader which you can either set in the server config, or directly in the page.

请记住,在服务器端,您必须启用 CORS才能在 Firebug 中查看响应(否则,将发送请求,但您将无法在 Firebug 中看到响应;不过您可以在Fiddler 中看到它);如果您在页面上打开 Firebug http://foo/somepage,那么该 URL 将由 XHR 在 HTTP 引用标头字段中发送,并且必须允许该域通过Access-Control-Allow-Origin标头接收 XHR 响应,您可以在服务器配置中设置,也可以直接设置在页面中。

Example in PHP:

PHP 中的示例:

<?php
header('Access-Control-Allow-Origin: *');
//you can adjust it more fine-grained, perhaps in an 'if'
//header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
//header('Access-Control-Allow-Origin: http://foo');

echo $_POST['a'] . "\r\n";
echo $_POST['b'] . "\r\n";
echo $_GET['w'] . "\r\n";
?>

Then you can use Firebug's Nettab to inspect the response (and also in the Consoletab if you have Console > RIGHT CLICK > Show XMLHttpRequestoption enabled).

然后您可以使用 Firebug 的Net选项卡来检查响应(Console如果您Console > RIGHT CLICK > Show XMLHttpRequest启用了选项,也可以在选项卡中)。

回答by T.Todua

No plugins needed.

不需要插件。

You can simply do it with inline javascript button: https://stackoverflow.com/a/38643171/2377343

您可以简单地使用内联 javascript 按钮来完成:https: //stackoverflow.com/a/38643171/2377343