I'm trying to come up with the most appropriate way to make a two-way socket connection through an HTTP proxy - let's say this is a protocol like telnet. Unfortunately, I also need to support NTLM authentication (with a proxy server), as well as Basic and Digest, in addition to any other future authentication mechanisms that I cannot predict.
If it were just a basic and digest, I would handle the connection myself, but I really do not want to get stuck in a swamp, which is NTLM. If you look at the basic AuthenticationManager API, it is very attached to HttpWebRequest, so I cannot use this function if I use socket / tcpclient / whatever or even write new WebRequest output.
Playback with HttpWebResponse gives a stream that cannot be recorded using RequestStream after the response stream has been restored, giving a parallel io exception.
After going through all the possibilities that I can think of, I came up with some nasty code that gives NetworkStream related to HttpWebRequest, which allows two-way communication:
..... HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); Stream str = resp.GetResponseStream(); System.Type type = str.GetType(); PropertyInfo info = type.GetProperty("Connection", BindingFlags.NonPublic|BindingFlags.Instance| BindingFlags.Public); object obj = info.GetValue(str, null); type = obj.GetType(); info = type.GetProperty("NetworkStream", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); object obj2 = info.GetValue(obj, null); NetworkStream networkStream = obj2 as NetworkStream;
Which I'm pretty pushed away (it won't work with Mono for starters), so I'm wondering if there is a better way to use public APIs that will allow me to use the built-in proxy authentication functionality.
source share