http - Java get the default proxy -


is there way "behind-the-scenes" proxy in java? 1 specified http.proxyhost , http.proxyport.

if do:

url url = new url("http://google.com"); httpurlconnection con = (httpurlconnection) url.openconnection(); 

it automatically connects through values set above. can specify proxy (httpurlconnection con = (httpurlconnection) url.openconnection(proxy.no_proxy);). how can specify default proxy?

for example, have method , want open connection "default proxy" (which same thing proxy.no_proxy if http.proxyhost , http.proxyport aren't set)? use

(httpurlconnection) ((proxy == null) ? url.openconnection() : url.openconnection(proxy)) 

but there away do

(httpurlconnection) url.openconnection(proxy == null ? [the default proxy] : proxy) 

i tried getting default proxy with

public static proxy getcurrenthttpproxy(proxy defaultproxy) {     string proxyhost = system.getproperty("http.proxyhost");     string proxyport = system.getproperty("http.proxyport");     if (proxyhost == null || proxyport == null) {         return defaultproxy;     }     return new proxy(proxy.type.http, new inetsocketaddress(proxyhost, integer.parseint(proxyport))); } 

but still need make special case , check https proxy settings. (if url http, call getcurrenthttpproxy, if url https, call getcurrenthttpsproxy). looked proxyselector (like here how default proxy settings in java program (not applet)?) seems clumsy this.

lastly, tried looking openjdk's implementation, seems open connection default proxy if passed parameter null, when tried on sun jvm , gives nullpointerexception.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -