HTTP get request

    0

    7

    http
    Java Public Recipes

    Make get request with the standard library

    import java.net.http.HttpResponse;
    import java.net.http.HttpRequest;
    import java.net.http.HttpClient;
    import java.net.URI,java.io.IOException;
    
    try {
      HttpClient client = HttpClient.newHttpClient();
      HttpRequest request = HttpRequest.newBuilder().uri(URI.create(yourUri)).build();
      HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
    } catch (IOException e) {
      // I/O exception handling
    } catch (InterruptedException e) {
     // request interrupted
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.