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.
1
  • I am a Windows user.
    – Rishav
    Commented Feb 28, 2018 at 13:11

3 Answers 3

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:[email protected]: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.

1
  • 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
    Commented Feb 28, 2018 at 13:09
0

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

-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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.