Hello, I need advice, there is a program written in c # there is its source code, it is necessary that the program works in the same way but through a proxy. I need a method to specify the proxy through the program, and not through the browser itself, since the proxy will regularly change and load from the file, but I know how to do it, but I don’t know how to add this proxy installation function to the program.

Proxies come with authorization, so I found several solutions in Google, but I don’t know how to properly implement this code into the program.

I even found an example on stackoverflow .

There is also an example for Gecko firefox , but I have the usual one: My main code is:

using HtmlAgilityPack; using OpenQA.Selenium; using OpenQA.Selenium.Support.UI; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Net; using System.Threading; namespace RPost { public static class RotaPostWorker { public static WorkerAuthorizeAndRefsToTask _S1_Get_Task_Windows(InputInfo input, CurrentInfo current) { WorkerAuthorizeAndRefsToTask authorizeAndRefsToTask = new WorkerAuthorizeAndRefsToTask(); LogSystem.ShowLogMessage("Запускаем окно браузера"); IWebDriver rotapostBrowser = Settings.RotapostBrowser; try { string url1 = current.auth_info.Web; LogSystem.ShowLogMessage("Переходим на ссылку " + current.auth_info.Web); rotapostBrowser.Navigate().GoToUrl(url1); 

But I don’t quite understand where I have to embed a piece of code with stackoverflow. All the time different errors are issued, you may first need to include some other library. I really hope for your help.

  • Are you sure that a piece of code with StackOverflow can just be thoughtlessly inserted into the program and it will work? Why don't you figure out what exactly this piece does? - VladD
  • No, I know that this is impossible so I wrote it here, that piece of code edits the firefox profile setting the proxy - Nikolay1112
  • I found out that I don’t even need to change the proxy myself every time, it remains to find out how you can only set the login and password which commands to use in c # to specify the data in the popup window - Nikolay1112

1 answer 1

  1. Selenium hyper lousy works with a proxy. Not just lousy, but hyper lousy. Consider that such a possibility in fayarfoks or chrome is just not stupid. I figured out quite well with selenium, but I spent a few days on this and did not figure it out. I even saw on the freelance exchange an offer to pay 50 bucks to show the developer how to get around this. he tried to figure it out himself for a week (and he even clarified: “if you haven’t done it before, don’t grab this job. I myself have a lot of experience and couldn’t figure it out”)

  2. But it works with phantomJS. Here is a sample code:

v

 var userAgent = @"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0"; var currDirr = Directory.GetCurrentDirectory() + "\\" + "phantomjs.exe"; string proxyHostStr = string.Format("{0}:{1}", proxyHost, proxyPort); string proxyAuth = string.Format("{0}:{1}", proxyLogin, proxyPassword); var serviceJs = PhantomJSDriverService.CreateDefaultService(); serviceJs.HideCommandPromptWindow = true; serviceJs.SslProtocol = "tlsv1"; serviceJs.IgnoreSslErrors = true; serviceJs.LoadImages = false; serviceJs.AddArguments("--proxy=" + proxyHostStr, "--proxy-type=http", "--proxy-auth=" + proxyAuth); var options = new PhantomJSOptions(); options.AddAdditionalCapability("phantomjs.page.settings.userAgent", userAgent); Instance = new PhantomJSDriver(serviceJs, options, TimeSpan.FromSeconds(180)); 

thus, it is quite possible to launch a browser with a proxy using selenium. Although it will be phantomJS. But it must be borne in mind that many problems may be associated with it. engine yet not like chrome or fox. And sites for this engine is not always sharpened.