使用套接字获取内容长度
谁能指导我仅使用套接字获取网站的 POST 内容长度。谢谢和荣誉! (由于某种原因我避免使用 httpwebrequest )
Can anyone guide me in acquiring the POST content-length of a website by just using sockets. Thanks and Kudos!
(I'm avoiding using httpwebrequest for some reason)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果它是代理应用程序,则根本不需要解析标头。您只需将数据以字节形式从一侧镜像到另一侧。您需要解析的唯一内容是例如初始 HTTP CONNECTION 请求,或者与客户端的初始握手导致您建立上游连接的任何内容。剩下的只是字节复制、EOS 和错误传播。
If it's a proxy application you don't need to be parsing headers at all. You just need to mirror the data from one side to the other, as bytes. The only thing you need to parse is for example the initial HTTP CONNECTION request, or whatever your initial handshake with the client is that causes you to set up the upstream connection. The rest of it is just byte copying and EOS and error propagation.
在 Http 协议中,标头与内容通过双 crlf 分隔开。
因此,您可以解析标头并获取 Content-Length 标头,也可以计算出内容的长度(因为您知道标头在哪里结束、内容在哪里开始)。
In the Http protocol the header is seperated from the content by a double crlf.
So you could either parse the header and get the Content-Length header or you can figure out the length of the content (since you know where the header ends and content starts).
HTTP/1.1 消息长度规则在 RFC 2616 的 4.4 节。
HTTP/1.1 message length rules are described in section 4.4 of the RFC 2616.