I'm trying to write a local proxy application. I know how proxy applications work in theory.
I've done everything related to handle incoming connections. But the problem is how should I send request which client requested to specified Url. When I try to create a connection with TcpClient
to specified Url and port, it throws following exception :
No such host is known
Edit : I think I should bypass the proxy something like FireFox is doing even system proxy set.
Any idea will be helpful.
Thanks in advance.
These links might be of help:
Based on colinsmith provided links, I've done to bypass proxy using TcpClient. Here is how I did that :
public static TcpClient CreateTcpClient(string url)
{
var webRequest = WebRequest.Create(url);
webRequest.Proxy = null;
var webResponse = webRequest.GetResponse();
var resposeStream = webResponse.GetResponseStream();
const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;
var rsType = resposeStream.GetType();
var connectionProperty = rsType.GetProperty("Connection", flags);
var connection = connectionProperty.GetValue(resposeStream, null);
var connectionType = connection.GetType();
var networkStreamProperty = connectionType.GetProperty("NetworkStream", flags);
var networkStream = networkStreamProperty.GetValue(connection, null);
var nsType = networkStream.GetType();
var socketProperty = nsType.GetProperty("Socket", flags);
var socket = (Socket)socketProperty.GetValue(networkStream, null);
return new TcpClient { Client = socket };
}
Hope this help for others.