HTTP: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: fixed libheader) |
(Updated the Java example to use the modern standard HTP Client API) |
||
Line 1,277: | Line 1,277: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
Using the standard [http://openjdk.java.net/groups/net/httpclient/ Java 11 HTTP Client] |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
import java.net.http.HttpRequest; |
|||
import java.net.http.HttpResponse; |
|||
import java.nio.charset.Charset; |
|||
public class Main { |
public class Main { |
||
public static void main(String[] args) |
public static void main(String[] args) { |
||
var request = HttpRequest.newBuilder(URI.create("https://www.rosettacode.org")) |
|||
.GET() |
|||
.build(); |
|||
HttpClient.newHttpClient() |
|||
.sendAsync(request, HttpResponse.BodyHandlers.ofString(Charset.defaultCharset())) |
|||
.thenApply(HttpResponse::body) |
|||
.thenAccept(System.out::println) |
|||
.join(); |
|||
} |
} |
||
} |
} |