Add an HttpProxyClient for use with the various protocol clients
See original GitHub issueDescribe the bug I have successfully tested the mailkit imap class with 2 differents imap account (outlook and gmail) without using proxy I am not able to connect to our http proxy in any mode, i don’t have a socks proxy. The connection to the proxy is Ok but when i call the connect method i have the error posted below. This is the code i have used. What i am doing wrong?
To Reproduce
client = new ImapClient(new ProtocolLogger("imap.log"))
{
ServerCertificateValidationCallback = (s, c, h, e) => true,
CheckCertificateRevocation = false
};
string proxyServer = "192.168.16.19";
int proxyPort = 8080;
string proxyUsername = "admin";
string proxyPassword = "password";
string b64UserPwd = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(proxyUsername + ":" + proxyPassword));
Socket mySocket = new Socket(SocketType.Stream, ProtocolType.Tcp);
mySocket.Connect(proxyServer,proxyPort);
string connectMsg = string.Format("CONNECT {0}:{1} HTTP/1.0\r\n" + "Proxy-Authorization: Basic {2}\r\n" + "\r\n",
proxyServer,
proxyPort,
b64UserPwd);
byte[] msg = Encoding.UTF8.GetBytes(connectMsg);
mySocket.Send(msg);
string proxyConnectionResponseHeader = "";
while (!proxyConnectionResponseHeader.Contains("\r\n\r\n"))
{
byte[] buffer = new byte[1];
mySocket.Receive(buffer, 0, 1, 0);
proxyConnectionResponseHeader += Encoding.ASCII.GetString(buffer);
}
if (!proxyConnectionResponseHeader.Contains("200 Connection established"))
{
throw new Exception("Connection to Proxy Failed: " + proxyConnectionResponseHeader);
}
var mode = _appModel.UseSSL ? SecureSocketOptions.SslOnConnect : SecureSocketOptions.None;
client.Connect(mySocket,
_appModel.Server,
_appModel.Port,
mode);
Screenshots
Desktop (please complete the following information):
- OS: Windows 10
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
Use the Proxy Protocol to Preserve a Client's IP Address
In this blog post, you'll learn how the Proxy Protocol preserves a client's IP address when that client's connection passes through a proxy....
Read more >http-proxy-client-async v0.3.1
Async I/O HTTP 1.1 CONNECT proxy client protocol implementation.
Read more >Proxy Protocol with Nginx Reverse Proxy
1 Answer 1 · Use the proxy_bind directive (cf. proxy_bind) to tell nginx to spoof its source address (to use the one from...
Read more >HTTP Proxy Client Configuration - LogScale Documentation
LogScale will use the proxy for sending messages from actions and communicating with S3. To set up an HTTP proxy, use the following...
Read more >12 HTTP Client and Web Debugging Proxy Tools
This tool provides an HTTP command for sending requests, all with the use of a natural syntax. HTTPie can be used for debugging,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Try the MyGet package once it’s published by the build bots (next 30 minutes or so?) and use
MailKit.Net.Proxy.HttpProxyClient
.(Note: the main MailKit github page provides download links to official NuGet release packages as well as MyGet CI builds)
@Safirion I have used this code https://github.com/poma/ProxySocket/blob/master/src/Org.Mentalis.Network.ProxySocket/ProxySocket.cs and it works. @jstedfast maybe it can be used to create a standard implementation in mailkit?