Fiddler:创建自动响应规则以将对一台主机的所有呼叫映射到另一台主机

发布于 2024-12-12 20:14:20 字数 987 浏览 1 评论 0原文

例子: 我想创建一个自动响应规则,将对一台主机的所有调用映射到另一台主机,但保留网址。示例

http://hostname1/foo.html -> http://hostname2/foo.html

http://hostname1/js/script.js -> http://hostname2/js/script.js

在一条规则中。 目前,我已经通过为我的项目调用的每个 URL 创建一个自动响应规则来完成此任务,但我确信必须有一种方法使用正确的通配符来纠正一个规则。我查看了 http://www.fiddler2.com/Fiddler2/help/AutoResponder.asp< /a>,但我不知道该怎么做。通配符似乎都围绕着匹配而不是动作。

完整上下文:我正在测试版平台上进行开发,而 Visual Studio 陷入困境,它将所有请求发送到 http ://localhost:24575 当我的项目实际运行在 http://localhost:56832

Example:
I want to create one AutoResponse rule that will map all calls to one host to another host, but preserve the urls. Examples

http://hostname1/foo.html -> http://hostname2/foo.html

and

http://hostname1/js/script.js -> http://hostname2/js/script.js

in one rule.
For now, I've accomplished this by creating aN AutoResponse rule for every URL my project calls, but I'm sure there must be a way to right one rule using the right wildcards. I looked at http://www.fiddler2.com/Fiddler2/help/AutoResponder.asp, but I couldn't see how to do it. The wild cards all seem to be around the matching and not the action.

Full context: I'm developing on a beta platform and Visual Studio is borked in such away that it is sending all the requests to http://localhost:24575 when my project is actually running on http://localhost:56832

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

記柔刀 2024-12-19 20:14:20

这就是我配置 Fiddler2 的方式:

I want to redirect all requests from http://server-name/vendor-portal-html/ to http://localhost/vendor-portal-html/ 

我的配置如下:

REGEX:.*/vendor-portal-html/(.*)   to    http://127.0.0.1/vendor-portal-html/$1

在此处输入图像描述

感谢 EricLaw 的上述评论。

This is how I configured Fiddler2 :

I want to redirect all requests from http://server-name/vendor-portal-html/ to http://localhost/vendor-portal-html/ 

My configuration is as follows:

REGEX:.*/vendor-portal-html/(.*)   to    http://127.0.0.1/vendor-portal-html/$1

enter image description here

Thanks to EricLaw for above comment.

风吹短裙飘 2024-12-19 20:14:20

要从一台主机映射到另一台主机,请勿使用自动响应程序。相反,单击“工具”>“主持人。

或者,您可以单击“规则”>“规则”。自定义规则,滚动到 OnBeforeRequest 并编写一些代码:

if (oSession.HostnameIs("localhost") && (oSession.port == 24575)) oSession.port = 56832;

To map from one host to another, don't use AutoResponder. Instead, click Tools > Hosts.

Alternatively, you can click Rules > Customize Rules, scroll to OnBeforeRequest and write a bit of code:

if (oSession.HostnameIs("localhost") && (oSession.port == 24575)) oSession.port = 56832;
十级心震 2024-12-19 20:14:20

因为这比使用 Fiddler 将所有请求重定向到另一台主机要困难得多:

使用 AutoResponder 选项卡设置规则,以便任何请求都与您的旧主机匹配将重定向到您的新主机,并附加路径和查询字符串。

与正则表达式选项 ix 匹配,使其不区分大小写并忽略空格。将 n 选项保留为

捕获请求的路径和查询字符串,并使用变量 $1 将其附加到重定向响应,其中路径+查询是第一个捕获组。如果您的正则表达式有更多捕获组,则可以使用捕获组 $1-$n

然后,Fiddler 将发出 HTTP 307 重定向响应。

请求:regex:^(?ix)http://old.host.com/(.*)$ #Match HTTP host

响应:*redir:http://new.host .com/$1

将旧主机重定向到新主机主机

请求

GET http://old.host.com/path/to/file.html HTTP/1.1
Host: old.host.com
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive

响应

HTTP/1.1 307 AutoRedir
Content-Length: 0
Location: http://new.host.com/path/to/file.html
Cache-Control: max-age=0, must-revalidate

Because this was way harder to find than it should have been to use Fiddler to redirect all requests for one to host to another host:

Use the AutoResponder tab to set a rule such that any request matching your old host will redirect to your new host with the path and query string appended.

Match with regex options ix to make it case-insensitive and ignore whitespace. Leave off the n option as it requires explicitly named capture groups.

Capture the path and query string of the request and append it to the redirect response using the variable $1, where the path+query is the first capture group. You can use capture groups $1-$n if your regex has more.

Fiddler will then issue an HTTP 307 redirect response.

Request: regex:^(?ix)http://old.host.com/(.*)$ #Match HTTP host

Response: *redir:http://new.host.com/$1

Redirect old host to new host

Request

GET http://old.host.com/path/to/file.html HTTP/1.1
Host: old.host.com
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive

Response

HTTP/1.1 307 AutoRedir
Content-Length: 0
Location: http://new.host.com/path/to/file.html
Cache-Control: max-age=0, must-revalidate
大姐,你呐 2024-12-19 20:14:20

可以使用正则表达式将请求与 Fiddler 自动应答器映射。
这可以通过 rexexp 规则来完成。然而,这似乎没有在任何地方记录。

如果添加规则并在括号内使用正则表达式,则在使用占位符时,可以在所需的映射中使用这些匹配项 ... $n

每个数字对应于规则中匹配的正则表达式。

Example of Rule: regex:http://server1/(\w*) -> http://server2/

This will result in the following mapping: http://server1/foo.html -> http://server2/foo.html

Mapping requests with Fiddler Autoresponder using Regular Expressions is possible.
This can be done with rexexp rules. However this doesn't seem to be documented anywhere.

If you add a rule and use regular expressions within parenthesis, these matches can be used in the desired mapping when using the placeholders ... $n

each number corresponds to the matched regexp in the rule.

Example of Rule: regex:http://server1/(\w*) -> http://server2/

This will result in the following mapping: http://server1/foo.html -> http://server2/foo.html
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文