我在这里有一个简单的python 3代码,可在localhost:8080上侦听。
import socket
clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientSocket.bind(("127.0.0.1", 8080))
clientSocket.listen(1)
while True:
try:
(connection, address) = clientSocket.accept()
browser_request = connection.recv(99999)
print(browser_request.decode())
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serverSocket.settimeout(5)
serverSocket.connect(("127.0.0.1", 1080))
serverSocket.send(browser_request)
response = serverSocket.recv(9999);
print(response.decode())
connection.send(response)
except Exception as e: print(e); pass
它获取浏览器请求并将其重定向到在本地主机上监听的代理服务器:1080(我使用shadowsocksR代理BTW)
“ HTTP”连接有效,并将数据发送回我的浏览器。 但是当涉及到https时,就会发生