Communicating with an HTTP Proxy via a .NET TcpClient

北慕城南 提交于 2019-12-18 10:47:15

问题


How can I communicate through an HTTP proxy with TcpClient in C#, kind of like WebProxy when using HttpWebResponse?


回答1:


Well, TCP doesn't have anything directly equivalent to HTTP proxying. In HTTP, the client (generally) knows about the proxying - it talks to the proxy, and asks the proxy to connect to the real web server on its behalf.

TCP doesn't define that sort of thing, so any proxying would have to either be transparent (i.e. something that a router or the operating system does without the client knowing, e.g. with iptables) or as part of the protocol on top of TCP (HTTP proxying is a good example of this, as is SOCKS mentioned in a different answer).




回答2:


If you go down to low-level socket programming, I'm pretty sure you'll need to write your own proxy client. If you're only dealing with the HTTP protocol, you're probably better off using HTTP-specific classes. If you need to do it with sockets, the HTTP spec describes the behavior of proxies reasonably well, so you could write your own client.




回答3:


If you'd like to use a SOCKS proxy, there are already some SOCKS libraries written for C#. Try this one.



来源:https://stackoverflow.com/questions/691550/communicating-with-an-http-proxy-via-a-net-tcpclient

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!