如何捕获 URL 或 HTTP 请求并使用 C# 重定向它

发布于 2024-11-06 09:19:43 字数 554 浏览 2 评论 0原文

大家好,感谢您的阅读。

对于 QA 方式,我想设置一个应用程序,可以处理和管理特定运行应用程序通过互联网发送的请求和数据。

更具体地说,我希望能够重定向几个网址,而不是每个网址,以通过“代理应用程序”工作,因此,如果我有一个请求 http://www.google.comhttp://www.google .com/search,我只想重定向第二个指向相对路径 /search 的路径。

我希望你能明白。 你们有什么简单实现的想法以及可能有一个现有的框架来实现这一点吗?如果您至少给我一些带有示例的代码,我将不胜感激。

提前致谢。

更新:事实上,我需要构建一个应用程序,该应用程序可以以某种方式“附加”到并劫持已开发的应用程序和数据服务器之间的现有连接,以便它可以侦听和修改通过这个连接。我知道用 C# 这样的高级语言很难完成,但我只是想确保

Hello everyone and thanks for reading.

For means of QA, I want to setup an application that could handle and manage the requests and the data sent through the internet from an especific running application.

More specifically, I want to be able to redirect a few urls, not every one, to work via a "proxy application", so if I have an application that requests http://www.google.com AND http://www.google.com/search, I would want to redirect only the second one poiting to the relative path /search.

I hope you get the idea.
Do you guys have any ideas for an easy implementation and maybe an existing framework to accomplish that? I would be thankful if you give me at least some piece of code with an example.

Thanks in advance.

Update: In fact, I needed to build an application that could somehow be "attached" to and hijack an existing connection between the already developed application and the data server so it could listen and modify the data sent through this connection. I know its hard to accomplish in a high level language like c# but I just wanted to make sure

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

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

发布评论

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

评论(1

爱人如己 2024-11-13 09:19:43

我不确定我是否正确理解了您的意思...您想将某些 URL 重定向到“代理应用程序”???不是代理服务器?

如果你想重定向到代理服务器,那么你可以这样做:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/search/");
request.proxy = new WebProxy("http://proxyurl");
HttpWebResponse myWebResponse=(HttpWebResponse)myWebRequest.GetResponse();

或者没有代理服务器:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
HttpWebResponse myWebResponse=(HttpWebResponse)myWebRequest.GetResponse();

你可以让“代理应用程序”提供 URL,但这是一个完全不同的故事。在这种情况下,您将需要在您的应用程序和其他应用程序之间进行某种通信方法。您的应用可以通过 TCP、通过 WCF通过管道。您将 URL 发送到其他应用程序,它会为其提供服务。

然后是另一部分:代理应用程序是否将页面返回给请求处理应用程序,还是将其提供给客户端?那么客户端如何与您的请求处理应用程序进行通信呢?

更新
听起来您正在寻找类似 Fiddler 的东西:

Fiddler 使您能够检查所有 HTTP 流量、设置断点以及“摆弄”传入或传出数据。 Fiddler 比 NetMon 或其他网络调试器使用起来简单得多,因为它仅公开 HTTP 流量,并且以用户友好的格式进行。

一般来说,您可能需要研究流量拦截

I'm not sure I follow you correctly... you want to redirect certain URLs to a "proxy application"??? Not a proxy server?

If you want to redirect to a proxy server then you can do this:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/search/");
request.proxy = new WebProxy("http://proxyurl");
HttpWebResponse myWebResponse=(HttpWebResponse)myWebRequest.GetResponse();

Or without a proxy server:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
HttpWebResponse myWebResponse=(HttpWebResponse)myWebRequest.GetResponse();

You can let a "proxy application" serve the url, but that's a completely different story. In that case you will need some method of communication between your application and the other application. Your app can connect to the other app via TCP, via WCF or via Pipes. You send the URL to the other application and it serves it.

Then comes the other piece: does the proxy application serve the page back to your request handling application or does it serve it to the client? So how is the client communicating with your request handling application?

Update
It sounds like you're looking for something like Fiddler:

Fiddler enables you to inspect all HTTP traffic, set breakpoints, and "fiddle" with incoming or outgoing data. Fiddler is much simpler to use than NetMon or other network debuggers because it exposes only HTTP traffic and does so in a user-friendly format.

In general you might want to look into traffic interception.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文