Intercept an HTTP request at browser end to alter some html content

后端 未结 11 1698
灰色年华
灰色年华 2021-02-06 19:43

I would like to do as follows. What would be the best way? A general answer will also be fine.

I would like to intercept an HTTP request at the client end to alter some

相关标签:
11条回答
  • 2021-02-06 19:49

    or, you can code a toolbar, or maybe a simple chrome addon, it's really easy but its not C#

    you can search for libraries to monitor browsing trough proxy, like this:

    http://httpproxynet.codeplex.com/

    The same concept used by java in this project: http://www.charlesproxy.com/

    sounds intresting, good luck :)

    0 讨论(0)
  • 2021-02-06 19:50

    Asynchronous Pluggable Protocols can be used for this type of thing. Although, as stated here INFO: Implementing HTTP-like Asynchronous Pluggable Protocols: "For various reasons, Microsoft neither supports nor recommends that you replace or wrap the default HTTP protocol."

    0 讨论(0)
  • 2021-02-06 19:51

    Are you saying you want to intercept this for your own site?

    In any case, it needs to be done in javascript or jQuery as C# is not a client-side language.

    0 讨论(0)
  • 2021-02-06 19:55

    Local HTTP proxy is possible and most generic approach.

    I.e. you can use Fiddler to see if it works for you. I supports modifying requests/responses in addition to regular watching for traffic.

    0 讨论(0)
  • 2021-02-06 19:55

    Such an approach is the least efficient method of doing what you want to achieve.

    If this is a client side application, the client may disable it and thus render it useless. It is also hard to maintain and requires more complex programming to ensure that it works with SSL.

    • If using a browser plugin, or toolbar, it would need to be made for a specific browser.
    • If using a listening server to intercept the HTTP request, this provides complexity and difficulty when the content is encrypted, also unnecessary overhead.
    • If using a local proxy (meaning that the client's browser needs to point to a local proxy service), maybe the most effective client side method, but still have the disadvantages mentioned above (hard to maintain etc.)

    I believe that what you are looking to do is completely reinventing the wheel.

    The fact that you have offered a bounty begs the question that you indeed need to do this in C# and client side, but 'censoring bad things' means you need to prohibit content, and any client side method would eventually give the power to the client to remove this limitation.

    Personally, I have had great success with Squid and it's content adaptation features.

    This means, that the clients need to have a controlled Internet source. Meaning that, if they are all in a LAN and sharing a common Internet gateway, this is easily feasible if you have spare a server to act as a proxy.

    I recommend you get a small linux box, which can have a simple Ubuntu Server Edition, then add Squid. The net is full of tutorials, but the level of implementation has become easy enough to do even without them.

    I may have gone completely off-topic, but I hope I could assist.

    0 讨论(0)
  • 2021-02-06 19:59

    You could setup a proxy with HTTPListener. But I would think if you wanted to do it right, you'll need a program that is more low level.

    • Open 2 TCP Ports (80 & 443) and actively listen for incoming connections.
    • Once received
      • Go out and make the request on behalf of the requester
    • Retrieve HTTP Response
    • Inspect and change the HTTP Response (where appropriate)
      • Perhaps modifying headers (where appropriate)
    • Forward on the response to the requester

    I'd start with a simple proxy that just forwards all requests and returns back all responses. Once that is in place you can start inspecting the responses.

    That is a good place to start.

    0 讨论(0)
提交回复
热议问题