首页 文章

TCP套接字侦听器 - 请求从POST更改为GET?

提问于
浏览
0

我创建了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();

但是当我用我的机器的IP(191.151.43.22)替换'localhost'时 . 代理接收客户端请求作为“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时工作 .

1 回答

  • 0

    您的HTTP请求很可能会被代理服务器更改(我的猜测是您的路由器) .

    话虽如此,代理服务器(假设是罪魁祸首)可能与它正在做的事情不一致 . 我在您的请求中没有看到任何POST数据**,因此所做的更改应该对接收端没有任何功能影响 .

    **有GET数据(位于URL中),但没有POST数据(位于 Headers 之后) .

相关问题