如何拦截和修改服务器端的HTTP响应? [英] how to intercept and modify HTTP responses on server side?

查看:1204
本文介绍了如何拦截和修改服务器端的HTTP响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用HTTP的客户端/服务器应用程序,我的目标是为其添加新功能。我可以通过将自己的代码挂钩到某些特定事件来扩展客户端,但遗憾的是服务器无法自定义。客户端和服务器都在Windows环境中。

I am working with a client/server application which uses HTTP, and my goal is to add new features to it. I can extend the client by hooking my own code to some specific events, but unfortunately the server is not customizable. Both client and server are in a Windows environment.

我当前的问题是,当从服务器收到大量数据时性能很差:传输它需要时间和处理它的时间。解决方案可能是让服务器端的应用程序进行处理并仅发送结果(这要小得多)。问题是在发送服务器之前没有内置函数来处理来自服务器的响应。

My current problem is that performance is awful when a lot of data are received from the server: it takes time to transmit it and time to process it. The solution could be to have an application on server side to do the processing and send only the result (which is much smaller). The problem is there is not built-in functions to manipulate responses from the server before sending them.

我正在考虑收听端口80上的所有流量,识别相关的HTTP响应并将其发送到我的应用程序,同时阻止响应(以避免发送客户端不会处理的大量数据)。由于我缺乏大量的网络知识,在考虑如何做的时候我有点迷失。

I was thinking to listen to all traffic on port 80, identifying relevant HTTP responses and send them to my application while blocking the response (to avoid sending huge data volume which won't be processed by the client). As I am lacking a lot of network knowledge, I am a bit lost when thinking about how to do it.

我看了一些低级数据包拦截方法像WinPCap一样,但似乎需要做很多工作来完成我需要的工作。此外,我认为不可能使用此API阻止或修改响应。

I had a look at some low-level packet intercepting methods like WinPCap, but it seems to require a lot of work to do what I need. Moreover I think it is not possible to block or modify responses with this API.

允许用户脚本由特定请求或响应触发的反向代理将是完美的,但我想知道是否有更简单的方法来拦截/发送其他工作。

A reverse proxy which allows user scripts to be triggered by specific requests or responses would be perfect, but I am wondering if there is no simpler way to do this interception/send elsewhere work.

启用此行为的最简单,最干净的方法是什么?

What would be the simplest and cleanest method to enable this behavior?

谢谢!

推荐答案

我结束了制作一个简单的反向代理来访问HTTP服务器。然后,反向代理从服务器响应中提取相关信息并将其发送到服务器端处理组件,并用客户端用来请求其他组件获取处理结果的ID替换从响应中提取的信息。

http://www.codeproject.com/KB/web上的文章-security / HTTPReverseProxy.aspx 非常有助于制作反向代理的初稿。

I ended making a simple reverse proxy to access the HTTP server. The reverse proxy then extracts relevant information from the server response and sends it to the server-side processing component, and replaces information extracted from the response by an ID the client uses to request the other component to get the processing results.
The article at http://www.codeproject.com/KB/web-security/HTTPReverseProxy.aspx was very helpful to make the first draft of the reverse proxy.

这篇关于如何拦截和修改服务器端的HTTP响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆