Home
> Uncategorized > Make an HTTP via # over an Authenticated #proxy in C#

Make an HTTP request via #TCP over an Authenticated #proxy in C#

working-behind-proxy-network

If you ever find yourself reverting to writing HTTP code using TCPClient, do a double-think, since there is very few situations where you genuinely need to resort to writing TCP/IP code. You can do an Authenticated proxy call using standard HTTP calls, by just setting the networkCredentials on a WebProxy class.

However, if you’ve read this caveat, and you still insist that you need to write code at TCP/IP level, then here’s some code that demonstrates how to make a simple HTTPS get request via an Authenticated HTTP Proxy (Luminati)

The authentication token, which I’ve omitted below, for obvious is a base64 encoded version of your username : your password .

var tcp = new TcpClient(“zproxy.luminati.io”, 22225);
var stream = tcp.GetStream();

var connect = Encoding.ASCII.GetBytes(“CONNECT icanhazip.com:443 HTTP/.0n” +
“proxy-authorization: Basic XXXXXX==nn”);
stream.Write(connect, 0, connect.Length);
var rawStream = new StreamReader(stream);
rawStream.ReadLine();
var ssl = new SslStream(stream);
ssl.AuthenticateAsClient(“www.icanhazip.com”, null, SslProtocols.Tls12, false);
var strPostString = “GET / HTTP/1.0rn” +
“Host:www.icanhazip.comrn” +
“rn”;
var send = Encoding.ASCII.GetBytes(strPostString);
ssl.Write(send, 0, send.Length);
var sr = new StreamReader(ssl);
var str = sr.ReadToEnd();
tcp.Close();
ssl.Close();
return str;

 



Source link
thanks you RSS link
( https://blog.dotnetframework.org///11/make-an-http-request-via-tcp-over-an-authenticated-proxy-in-c/)

LEAVE A REPLY

Please enter your comment!
Please enter your name here