eclipse - Changing OS proxy settings using java -
can set/change proxy settings in windows 7 using java application?
i trying use:
public static void setproxy(string proxyurl, string proxyport){ system.getproperties().put("proxyset", "true"); system.getproperties().put("http.proxyhost", proxyurl); system.getproperties().put("http.proxyport", proxyport); }
but after run settings doesn't changed , have same ip had before.
even though of languages not allow (or) discourage change environment variables through program, can achieve jni in java using setenv()
, using processbuilder()
.
but why want change every 1 program? instead change variables in program context setting proxy server effective program run time context. that's how applications should designed , programmed.
here example, off top of head.
public static void main(string[] args) throws exception { processbuilder processbuilder = new processbuilder("cmd.exe", "/c", "set"); processbuilder.redirecterrorstream(true); map<string,string> environment = processbuilder.environment(); //set new envrionment varialbes here environment.put("proxyset", "true"); environment.put("http.proxyhost", proxyurl); environment.put("http.proxyport", proxyport); process process = processbuilder.start(); bufferedreader inputreader = new bufferedreader(new inputstreamreader(process.getinputstream())); string datalog=null; while ((datalog = inputreader.readline()) != null) { //just see what's going on process system.out.println(datalog); } }
note: again, discourage practice of changing environment variables program, instead set required ones context.
Comments
Post a Comment