我创建了 TCP 代理,它在端口 80(端口 80 未被任何其他服务使用)上侦听传入连接。当我使用“Localhost”或“127.0.0.1”作为侦听器套接字的 IpAddress 时,代理能够接收 POST 请求。
Socket listner = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint localEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 80);
listner.Bind(localEndpoint);
listner.Listen();
但是,当我将“localhost”替换为我机器的 IP(191.151.43.22)时。代理将客户端请求作为“GET 请求”接收
Socket listner = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint localEndpoint = new IPEndPoint(IPAddress.Parse("191.151.43.22"), 80);
listner.Bind(localEndpoint);
listner.Listen();
使用 localhost / 127.0.0.1 侦听连接时的客户端请求
POST /?toke=abc455/../Control.html?s=783&i=0&t=134 HTTP/1.1
Host: localhost:58888
Connection: keep-alive
Content-Length: 0
Origin: http://localhost:58888
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) C
hrome/21.0.1180.89 Safari/537.1
Content-Type: text/plain;charset=UTF-8
Accept: */*
Referer: http://localhost:58888/?toke=abc455/../Stream.html?s=0&d=%22
localhost%22&p=0&t=1348652703126
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: style=null
使用我的机器的 IP (191.151.43.22) 侦听连接时的客户端请求
GET /?token=abc344/../Stream.html?s=0&d=%22localhost%22&p=0&t=13486531
37269 HTTP/1.1
Host: 192.168.53.50
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) C
hrome/21.0.1180.89 Safari/537.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
为什么 POST 不使用系统的 IP 地址,但在使用 'localhost' 代替 IP 时工作。