简体   繁体   English

处理 POST 请求的简单 Python 代理服务器

[英]Simple Python Proxy server that handle POST requests

I am trying to build a simple proxy server in Python that serves as the middle person that monitors and retrieves all the requests/traffic that is passed between my web browser and the Internet.我正在尝试用 Python 构建一个简单的代理服务器,作为中间人,监控和检索在我的 Web 浏览器和 Internet 之间传递的所有请求/流量。 I found the following code:我找到了以下代码:

import SocketServer
import SimpleHTTPServer
import urllib

PORT = 1234

class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_GET(self):
        self.copyfile(urllib.urlopen(self.path), self.wfile)

httpd = SocketServer.ForkingTCPServer(('', PORT), Proxy)
print "serving at port", PORT
httpd.serve_forever()

But the example only handles GET requests.但该示例仅处理 GET 请求。 Is there a way for the proxy server to handle the POST requests traffic from the browser as well?代理服务器有没有办法处理来自浏览器的 POST 请求流量? Thank you so much for your help!非常感谢你的帮助! :) :)

just like you implemented do_GET , you can also implement do_POST in your Proxy class.就像你实现do_GET ,你也可以在你的Proxy类中实现do_POST This should probably work.这应该可以工作。 You can refer this .你可以参考这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM