Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Windows 下實作第 7 層軟負載經驗分享(4)

編輯:Win7 系統基礎知識

3. Cookie 處理

HttpWebRequest 不支援直接寫 Cookie,需建立 CookieContainer,收到回應後才有 Cookies。暫時做法:收到 RealServer 回應後將回應裡的 Cookies 複製給 ListenResponse 返回客戶端。

httpRequest.CookieContainer = new CookieContainer();
HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
listenResponse.Cookies = httpResponse.Cookies;

4. 逾時值難抉擇

httpRequest.Timeout = 20;
httpRequest.ReadWriteTimeout = 10;

分析結覺 HttpWebRequest 實現過於複雜、封裝太深,非為大量出站 HTTP 連線設計。HttpListener 尚可,專為 HTTP 伺服器設計。實在不行可用 Remoting 在 Proxy 與 RealServer 傳遞 HTTP 資訊再轉換。

Copyright © Windows教程網 All Rights Reserved