Search code examples
c#webproxyxnet

C# - xNet - how to add proxy support


I made a checker for some website, however, I need to add Proxy support:

using (var request = new HttpRequest())
{
       request.Proxy = new HttpProxyClient(ProxyRandom());
}

public static string ProxyRandom()
{
       Random rnd = new Random();
       return Proxies[rnd.Next(0, Proxies.Count)];
}

for some reason, it doesn't work... the program doesn't post any data when I try to use proxies

what is the right way to add proxy support when I use xNet library?


Solution

  • I have no idea what XNet is, however i looked at the GitHub

    As you can see from their example shown prominently on the page , you are trying to put the proxy in to the HttpRequest constructor which i assume is the Host Name, use request.Proxy property instead is my guess

    using (var request = new HttpRequest("Site name"))
    {
        request.UserAgent = Http.ChromeUserAgent();
        request.Proxy = Socks5ProxyClient.Parse("127.0.0.1:1080");