← Back to context

Comment by 999900000999

3 days ago

Google might step up soon and they already have a massive user base.

Google “How to send a get request using Java”.

>import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse;

public class GetRequestExample { public static void main(String[] args) { // Define the URL String url = "https://api.example.com/data";

        // 1. Create an HttpClient instance
        HttpClient client = HttpClient.newHttpClient();

        // 2. Create an HttpRequest object for a GET request
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .GET() // Default method, but good to be explicit
                .build();

        try {
            // 3. Send the request and receive the response synchronously
            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

            // 4. Process the response
            System.out.println("Status code: " + response.statusCode());
            System.out.println("Response body: " + response.body());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

Vs Chat GPT

> import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse;

public class GetRequestExample {

    public static void main(String[] args) throws Exception {

        HttpClient client = HttpClient.newHttpClient();

        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.example.com/data"))
                .GET()
                .build();

        HttpResponse<String> response = client.send(
                request,
                HttpResponse.BodyHandlers.ofString()
        );

        System.out.println("Status: " + response.statusCode());
        System.out.println("Body: " + response.body());
    }

}

Chat GPT is a bit clearer, but both are good.

It’s really Google’s race to lose, but we are talking about Google here. They’re very hit or miss outside of Search