ProxySelector.of(InetSocketAddress) in Java

ProxySelector.of(InetSocketAddress): This method is available in the java.net.ProxySelector class of Java.

Syntax:

ProxySelector java.net.ProxySelector.of(InetSocketAddress proxyAddress)

This method takes one argument. 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.

Parameters: One parameter is required for this method.

proxyAddress: The address of the proxy.

Returns: a ProxySelector.

Exceptions: NA

Approach

Java

package com.ProxySelector;

import java.net.InetSocketAddress;
import java.net.ProxySelector;

public class ProxySelectorof {
    public static void main(String[] args) {

        int port = 8080;
        InetSocketAddress proxyAddress = new InetSocketAddress(port);
        ProxySelector proxySelector = ProxySelector.of(proxyAddress);

        System.out.println(proxySelector);
    }
}

Output:

java.net.ProxySelector$StaticProxySelector@383534aa


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