我想在我正在工作的web应用程序中测试一些url。为此,我想手动创建HTTP POST请求(这意味着我可以添加任何我喜欢的参数)。

Chrome和/或Firefox中是否有我遗漏的功能?


当前回答

因此,我突然想到,您可以使用控制台,创建一个函数,并轻松地从控制台发送请求,其中将有正确的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数据。如果不是,则需要更改它以满足您的需要

其他回答

这是Chrome的高级REST客户端扩展。

它对我来说工作得很好——请记住,您仍然可以使用它的调试器。Network窗格特别有用;它会给你呈现JSON对象和错误页面。

您可以使用ReqBin直接从浏览器发出请求。 不需要插件或桌面应用程序。

查看http-tool for Firefox…

针对需要调试HTTP请求和响应的web开发人员。 在开发基于REST的API时非常有用。

特点: 得到 头 帖子 把 删除 向请求添加报头。 为请求添加主体内容。 响应的视图头。 在响应中查看正文内容。 查看响应状态码。 查看响应的状态文本。

Runscope试试。https://www.hurl.it/上提供了一个免费的工具来测试他们的服务。

可以设置方法、认证、报头、参数和正文。响应显示状态代码、报头和正文。响应体可以使用可折叠的层次结构从JSON格式化。

付费帐户可以自动测试API调用,并使用返回数据构建新的测试调用。

COI披露:我与Runscope没有关系。

你特别要求“在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操作。