1

I use RestClient to get pages over internet. Also this script I made is proxy enabled by using RestClient.proxy = "http://proxy.example.com/". But I dont always use proxy. So instead of manually setting proxy on and off inside the script I wanted the script to read system settings automatically.

The GitHub documentation states:

Often the proxy URL is set in an environment variable, so you can do this to use whatever proxy the system is configured to use:

RestClient.proxy = ENV['http_proxy']

I dont see how can this detect if system proxy in on or not here. It although can detect what proxy address I am using i suppose.

  • Also how specifically can I use this?
  • Also how do I specify the proxy port?
  • AND how can I get the system's proxy settings and then follow up with RestClient.proxy = "http://proxy.example.com/" IF proxy is enabled.
Rishav
  • 3,818
  • 1
  • 31
  • 49

3 Answers3

2

There's nothing magical about it.

http_proxy is assumed set by a user or administrator, and can be of the form http_proxy=http://username:password@proxy.example.org:8080 with both the credentials and port optional.

None of these magically import from the system; *nix systems generally don't have a "system proxy setting" and I don't think you can get at Windows' proxy settings determined in the network settings.

Joe
  • 41,484
  • 20
  • 104
  • 125
  • Okay I get the *actual way* by which i can use the port in the address but I can definitely set windows proxy by `system("REG ADD \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v ProxyEnable /t REG_DWORD /d 1 /f")` So is it not possible to read this registry as well some how? – Rishav Feb 28 '18 at 13:09
0

restClient.Proxy = new System.Net.WebProxy(yourProxyServer, yourProxyPort);

inon
  • 1,689
  • 1
  • 19
  • 34
-1

This answer tells how to add proxy via cmd. Maybe this could be of some use. You can run these commands using system(). You may not need to specifically specify proxy in RestClient. !UNTESTED! This also has an option for port. The windows proxy and terminal proxies are different.

So your 2nd and 3rd questions are answered hopefully.

  • Thanks but this is not my question. This way I still have to manually enter the proxy if i am using one. – Rishav Feb 28 '18 at 13:04