ProxySelector.setDefault(ProxySelector): This method is available in the java.net.ProxySelector class of Java.
Syntax:
void java.net.ProxySelector.setDefault(ProxySelector ps)
This method takes one argument. This method sets (or unsets) the system-wide proxy selector.
Note: non-standard protocol handlers may ignore this setting.
Parameters: One parameter is required for this method.
ps: The HTTP proxy selector, or null to unset the proxy selector.
Returns: NA
Throws:
1. SecurityException - If a security manager has been installed and it denies NetPermission("setProxySelector").
Approach
Java
package com.ProxySelector;import java.net.ProxySelector;public class ProxySelectorsetDefault {public static void main(String[] args) {ProxySelector ps = ProxySelector.getDefault();ProxySelector.setDefault(ps);System.out.println("Successfully sets default proxy selector");}}
Output:
Successfully sets default proxy selector
Some other methods of ProxySelector class
connectFailed(URI, SocketAddress, IOException): This method is called to indicate that a connection could not be established to a proxy/socks server.
getDefault(): This method gets the system-wide proxy selector.
ProxySelector.of(InetSocketAddress): This method returns a ProxySelector which uses the given proxy address for all HTTP and HTTPS requests. If the proxy is null then proxying is disabled.
select(URI): This method selects all the applicable proxies based on the protocol to access the resource with and a destination address to access the resource at.
ProxySelector.setDefault(ProxySelector): This method sets (or unsets) the system-wide proxy selector.
No comments:
Post a Comment