There is an old thread in stackoverflow about how make an HTTP request through a SOCKS proxy
But there is a problem in that solution.
For socks proxy in HttpWebRequest it tells use one of these two ways :
#1 this way is not free
#2 this way has many problems - First of all it is not complete - Second it does not support user-agent and cookies and accept headers.
For socks proxy in WebClient it tells use this class :
public class SocksWebClient : WebClient
{
public IProxyDetails ProxyDetails { get; set; }
public string UserAgent { get; set; }
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest result = null;
if (ProxyDetails != null)
{
if (ProxyDetails.ProxyType == ProxyType.Proxy)
{
result = (HttpWebRequest)WebRequest.Create(address);
result.Proxy = new WebProxy(ProxyDetails.FullProxyAddress);
if (!string.IsNullOrEmpty(UserAgent))
((HttpWebRequest)result).UserAgent = UserAgent;
}
else if (ProxyDetails.ProxyType == ProxyType.Socks)
{
result = SocksHttpWebRequest.Create(address);
result.Proxy = new WebProxy(ProxyDetails.FullProxyAddress);
//TODO: implement user and password
}
else if (ProxyDetails.ProxyType == ProxyType.None)
{
result = (HttpWebRequest)WebRequest.Create(address);
if (!string.IsNullOrEmpty(UserAgent))
((HttpWebRequest)result).UserAgent = UserAgent;
}
}
else
{
result = (HttpWebRequest)WebRequest.Create(address);
if (!string.IsNullOrEmpty(UserAgent))
((HttpWebRequest)result).UserAgent = UserAgent;
}
return result;
}
}
This class in not complete and no one mentioned what is IProxyDetails.
Finally i found this github way BetterHttpClient.
But it has error to work with socks5 proxies.
Here is the error :
An exception of type 'System.Net.WebException' occurred in System.dll but was not handled in user code
Additional information: The underlying connection was closed: The connection was closed unexpectedly.
Please give me a solution for that and tell me how Make an HTTP/S request through a SOCKS4/5 proxy | [useragent - cookies - accept] Support?