我已經有一個可以處理多個HTTP請求的正常工作的HTTP代理服務器。現在我的問題是如何處理https請求?創建一個接受HTTPS的Java代理服務器
這裏有一個簡單的代碼我使用:
class Daemon
{
public static void main(String[] args)
{
ServerSocket cDaemonSocket = new ServerSocket(3128);
while(true)
{
try
{
Socket ClientSocket = cDaemonSocket.accept();
(new ClientHandler(ClientSocket)).start();
}catch(Exception e) { }
}
}
}
和ClientHandler的
class ClientHandler extends Thread
{
private Socket socket = null;
private Socket remoteSocket = null;
private HTTPReqHeader request = null;
ClientHandler(Socket socket)
{
this.socket = socket;
request = new HTTPReqHeader();
request.parse(socket); // I read and parse the HTTP request here
}
public void run()
{
if(!request.isSecure())
{
remoteSocket = new Socket(request.url,request.port);
}
else
{
// now what should I do to established a secured socket?
}
// start connecting remoteSocket and clientSocket
...........
}
}
}
我真的嘗試搜索怎麼樣,我都遇到SSL隧道,證書,握手,SSLSocket,SSLFactory,trustStore等類似的東西,但仍然無法使它工作..我只需要知道我需要什麼東西和步驟來建立一個連接到啓用了SSL的Web服務器。
請閱讀[常見問題]和[問] – 2012-02-20 07:29:47
檢查http://stackoverflow.com/questions/516323/https-connections-over-proxy-servers和http://stackoverflow.com/questions/ 753191 /通過代理服務器訪問https站點,以瞭解HTTPS通過「代理」如何工作。 – 2012-02-20 07:43:39
@JimGarrison哦,很抱歉。下次我會盡力問好。只是迫切需要一個答案。 – 2012-02-22 04:12:06