我想在我正在工作的web应用程序中测试一些url。为此,我想手动创建HTTP POST请求(这意味着我可以添加任何我喜欢的参数)。
Chrome和/或Firefox中是否有我遗漏的功能?
我想在我正在工作的web应用程序中测试一些url。为此,我想手动创建HTTP POST请求(这意味着我可以添加任何我喜欢的参数)。
Chrome和/或Firefox中是否有我遗漏的功能?
当前回答
你特别要求“在Chrome和/或Firefox中的扩展或功能”,你已经收到的答案提供了这些,但我确实喜欢oezi对封闭问题“我如何使用web浏览器发送POST请求?”的简单参数的回答的简单性。oezi说:
在表单中,将方法设置为post
<form action="blah.php" method="post">
<input type="text" name="data" value="mydata" />
<input type="submit" />
</form>
例如,构建一个非常简单的页面来测试POST操作。
其他回答
对于Firefox,也有一个叫RESTClient的扩展,非常不错:
RESTClient,用于rest式web服务的调试器
我试着用邮差软件,有一些认证问题。 如果你必须专门使用浏览器,去网络选项卡,右键单击呼叫,说编辑和发送响应。这里有一个类似的关于Firefox的ans,这个右键点击为我工作在边缘,非常确定它也适用于chrome
受到Chrome版邮差的极大启发,我决定为Firefox写一些类似的东西。
REST Easy*是一个不可重启的Firefox插件,旨在对请求提供尽可能多的控制。该附加组件仍处于实验状态(Mozilla甚至还没有对其进行审查),但开发进展顺利。
这个项目是开源的,所以如果有人觉得有必要帮助开发,那就太棒了:https://github.com/nathan-osman/Rest-Easy
*从http://addons.mozilla.org上提供的附加组件将始终略落后于GitHub上提供的代码
在这里值得一提的是,在Postman崛起之后诞生了其他一些客户:
失眠:与桌面应用程序和Chrome插件 跳房子:以前被称为Postwoman,并与Chrome插件可用。你也可以让它在docker本地工作,如果你想变得有趣 Paw:如果你在Mac上 高级Rest客户端:作为Chrome插件已经提到过,但值得指出的是它也有一个桌面应用程序 soapUI:用Java写的,有很多测试功能 回旋镖:另一种测试api的方法。它带有SOAP集成,也有一个可用的Chrome插件 雷霆客户端:如果你使用VS Code作为你的文本编辑器,那么你应该去看看这个很棒的扩展
因此,我突然想到,您可以使用控制台,创建一个函数,并轻松地从控制台发送请求,其中将有正确的cookie等。
所以我在这里找到了这个:https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options
// Example POST method implementation:
async function postData(url = '', data = {}, options = {}) {
// Default options are marked with *
let defaultOptions = {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify(data) // body data type must match "Content-Type" header
}
// update the default options with specific options (e.g. { "method": "GET" } )
const requestParams = Object.assign(defaultOptions, options);
const response = await fetch(url, requestParams);
return response.text(); // displays the simplest form of the output in the console. Maybe changed to response.json() if you wish
}
如果你想GET请求,你可以把他们放在你的浏览器地址栏!
如果你把它粘贴到你的控制台,那么你可以通过重复调用你的函数来发出POST请求,就像这样:
postData('https://example.com/answer', { answer: 42 })
.then(data => {
console.log(data); // you might want to use JSON.parse on this
});
服务器输出将打印在控制台中(以及网络选项卡中可用的所有数据)
这个函数假设您正在发送JSON数据。如果不是,则需要更改它以满足您的需要