Java 有没有办法在 Chrome 或 Firefox 中修改 HTTP 请求?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22931720/
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-13 19:19:00  来源:igfitidea点击:

Is there a way to modify an HTTP request in Chrome or Firefox?

javaapachehttpgoogle-chrometomcat

提问by J. Lin

Is there a way to modify an HTTP request using Chrome dev tools or Firebug? For example when developing locally and testing in Chrome, I have a page that needs an HTTP request to fill some data. Because it's local, that service isn't available.

有没有办法使用 Chrome 开发工具或 Firebug 修改 HTTP 请求?例如在本地开发和在 Chrome 中测试时,我有一个页面需要一个 HTTP 请求来填充一些数据。因为它是本地的,所以该服务不可用。

Currently the only way of getting around the problem is configuring a proxy pass in Apache so it hits a QA environment for that call. I'm looking or a simpler way to achieve this because I use Jetty to test the app and can't configure a proxy pass (or that I know of).

目前,解决该问题的唯一方法是在 Apache 中配置代理传递,以便为该调用提供 QA 环境。我正在寻找一种更简单的方法来实现这一点,因为我使用 Jetty 来测试应用程序并且无法配置代理传递(或我知道的)。

In other words, is there a way to create a temporary proxy pass for the current session when testing an app locally?

换句话说,在本地测试应用程序时,有没有办法为当前会话创建临时代理通行证?

采纳答案by eis

For Chrome AFAIK request modification cannot be done due to api restrictions, see his threadfor additional discussion.

由于 api 限制,Chrome AFAIK 请求修改无法完成,请参阅他的线程以获取更多讨论。

However, you can use an app acting as a proxy like Fiddlerto have similar functionality for just about any browser.

但是,您可以使用充当Fiddler 等代理的应用程序,为几乎任何浏览器提供类似的功能。

For OSX, see these threads:

对于 OSX,请参阅以下主题:

回答by sachinjain024

Accepted answer is a bit old and there are many tools/extensions in chrome and Firefox which allows you to modify network requests.

接受的答案有点旧,chrome 和 Firefox 中有许多工具/扩展程序可以让您修改网络请求。

One such example is Requestly. Using Requestly you can do the following tasks:

一个这样的例子是Requestly。使用 Requestly,您可以执行以下任务:

  1. Redirect network requests.
  2. Block websites or specific requests.
  3. Switch domains using Replace Rule.
  4. Modify Headers
  5. Modify UserAgent Documentation1Documentation 2
  6. File Library(Host JS, CSS, JSON) and use them in Requestly rules
  1. 重定向网络请求。
  2. 阻止网站或特定请求。
  3. 使用替换规则切换域。
  4. 修改标题
  5. 修改 UserAgent文档 1文档 2
  6. 文件库(Host JS、CSS、JSON)并在 Requestly 规则中使用它们

There are more features but for your specific use case. You can host your js or css on library and redirect to it using Redirect Rule. If you have URL rewriting requirement, then you can use either Redirect or Replace rule.

还有更多功能,但适用于您的特定用例。您可以在库上托管您的 js 或 css 并使用重定向规则重定向到它。如果您有 URL 重写要求,那么您可以使用重定向或替换规则。

I won't say Requestly is as powerful as Fiddler or Charles but I'd say that it is pretty close with much simplistic UI.

我不会说 Requestly 与 Fiddler 或 Charles 一样强大,但我会说它与非常简单的 UI 非常接近。

Disclaimer: I built Requestly!

免责声明:我构建了 Requestly!

回答by Daniel Caldas

You can use tweakchrome extension and you'll be able to do exactly that, intercept and modify HTTP requests.

您可以使用调整chrome 扩展程序,您将能够做到这一点,拦截和修改 HTTP 请求。

回答by oriadam

This might help in some cases - use fetch command to send another, tampered, request. here's how to do it in Chrome:

这在某些情况下可能会有所帮助 - 使用 fetch 命令发送另一个被篡改的请求。以下是在 Chrome 中执行此操作的方法:

  1. open DevTools, tab Network
  2. clear
  3. create your request normally
  4. right click that request and select Copy > Copy as fetch
  5. go to Console tab and paste
  6. tamper the data and hit Enter
  1. 打开 DevTools,标签 Network
  2. 清除
  3. 正常创建您的请求
  4. 右键单击该请求并选择 Copy > Copy as fetch
  5. 转到控制台选项卡并粘贴
  6. 篡改数据并按 Enter

steps 1-4steps 5-6

步骤 1-4步骤 5-6