Communicating with an HTTP Proxy via a .NET TcpClient
Asked Answered
S

3

7

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

Sympathin answered 27/3, 2009 at 21:35 Comment(0)
P
8

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).

Purple answered 27/3, 2009 at 21:45 Comment(5)
@conker: I dare say the library Benton linked to is fine if you're using the kind of proxy server mentioned in his answer. That doesn't disagree with any part of my answer though.Purple
The question was simple, all other answers in this thread are to the point. Nobody was asking or answering about proxy server, especially not "that" or "other" "kind" of proxy server. It was about implementing proxy client on top of TCPClient. Stop talking our of your ass about things you have no idea about.Honshu
Well, I'm still pretty convinced that I do know what I'm talking about, and see no reason to delete this answer. If no-one was asking about any kind of proxy server, I do wonder what on earth anyone's going to talk to... there has to be something doing the proxying, and it's going to have to talk some appropriate protocol, isn't it?Purple
Your answer is not really helpful no matter how you look at it. Compare it with others, one is going into need of custom implementation on top of sockets (which is mostly correct), second gives link to partial solution, third is giving the most complete solution . Ironically, your answer gets the most votes and full solution gets no votes...Honshu
Um, every answer here has a vote. It looks like people disagree with you about whether or not it's "not really helpful no matter how you look at it". I suspect we'll just have to agree to disagree.Purple
B
3

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.

Boyes answered 27/3, 2009 at 21:45 Comment(0)
B
1

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

Bernetta answered 27/3, 2009 at 21:47 Comment(3)
How can I use that one in conjunction with TcpClient?Fite
Perhaps subclassing TcpClient would be best, but I don't think they're compatible. TcpClient is somewhat rigid in its usage, so it's not that flexible.Bernetta
Unfortunately the code in that article works with Socket, not TcpClient.Amine

© 2022 - 2024 — McMap. All rights reserved.