0
我想使用TcpClient
閱讀Https頁面。我用下面的代碼Http CONNECT請求返回空響應
var client = new TcpClient(url, 443);//"127.0.0.1", 8888);// Fiddler port
client.SendTimeout = 30000;
Stream responseStream = client.GetStream();
// send CONNECT request to server
byte[] tunnelRequest = Encoding.ASCII.GetBytes("CONNECT www.google.com:443 HTTP/1.1\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:44.0) Gecko/20100101 Firefox/35.0\r\nProxy-Connection: keep-alive\r\nConnection: keep-alive\r\nHost: www.google.com:443\r\n\r\n");
responseStream.Write(tunnelRequest, 0, tunnelRequest.Length);
responseStream.Flush();
// read CONNECT response
string connectResponse = ReadResponse(responseStream);
Console.WriteLine("server connect response : " + connectResponse);
即發送CONNECT
請求主機(google.com)
CONNECT www.google.com:443 HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0
Proxy-Connection: keep-alive
Connection: keep-alive
Host: www.google.com:443
必須輸入反應不會停這樣
HTTP/1.1 200 Connection Established
StartTime: 22:42:38.774
Connection: close
但responseStream
任何回報。當我使用提琴手作爲代理
var client = new TcpClient("127.0.0.1", 8888);
它工作正常,並返回200
響應。小提琴手修理它有什麼不對嗎?
我使用Windows 8.1並使用.Net 2和4.5.1進行測試。