HTTPCLIENT / CATATAN</>↗HttpClient06 Apr 2025
In Java 11, the HttpClient API was introduced as part of JEP 321, providing a standardized way to perform HTTP operations. To send a POST request with JSON data, you can use the HttpClient along with its HttpRequest object. Here’s a step-by-step guide and example: Steps to Send POST Request with JSON Data in Java […]
HTTPCLIENT / CATATAN</>↗HttpClient06 Apr 2025
In Java 11, you can use the HttpClient to send HTTP requests easily. Here’s how you can send a simple GET request using HttpClient: Full Example: package org.kodejava.net.http; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class SimpleGetRequestExample { public static void main(String[] args) { try { // Create an HttpClient instance HttpClient httpClient […]
CORE API / CATATAN</>↗Core API06 Apr 2025
Creating a proxy server using ProxySelector and Socket in Java involves a few steps. ProxySelector is used to determine which proxy to use for connections, while Socket facilitates communication with the client and/or the target server behind the proxy. Here’s a step-by-step guide: 1. Setup ProxySelector A custom ProxySelector can be created to define the […]
CORE API / CATATAN</>↗Core API05 Apr 2025
To bind a ServerSocket to a specific IP address in Java, you need to use one of the constructors or methods that allows you to specify the local address and port to bind to. Here’s how you can do it: Example Code: package org.kodejava.net; import java.io.IOException; import java.net.InetAddress; import java.net.ServerSocket; public class ServerSocketBindExample { public […]
CORE API / CATATAN</>↗Core API04 Apr 2025
To detect and list all network interfaces using NetworkInterface in Java, you can use the NetworkInterface.getNetworkInterfaces() method. This returns an Enumeration of all available network interfaces on the system. You can then iterate through this enumeration to fetch details of each interface, such as the name, display name, and associated IP addresses. Here is an […]
CORE API / CATATAN</>↗Core API03 Apr 2025
In Java, you can retrieve web content and parse HTML using the URL and URLConnection classes. Here’s a step-by-step guide along with an example: Steps to Retrieve Web Content Create a URL: Use the URL class to specify the web address. Open a Connection: Use the openConnection() method from the URL object to establish a […]