HTTP: Difference between revisions

390 bytes added ,  3 years ago
Updated the Java example to use the modern standard HTP Client API
m (→‎{{header|Phix}}: fixed libheader)
(Updated the Java example to use the modern standard HTP Client API)
Line 1,277:
 
=={{header|Java}}==
Using the standard [http://openjdk.java.net/groups/net/httpclient/ Java 11 HTTP Client]
<lang java5>import java.util.Scanner;
 
import java.net.URL;
<lang java5java>import java.utilnet.ScannerURI;
import java.net.URLhttp.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.Charset;
 
public class Main {
public static void main(String[] args) throws Exception {
Scannervar screquest = new ScannerHttpRequest.newBuilder(new URLURI.create("httphttps://www.rosettacode.org").openStream());
while (sc .hasNextGET())
System .out.println(sc.nextLinebuild());
 
HttpClient.newHttpClient()
.sendAsync(request, HttpResponse.BodyHandlers.ofString(Charset.defaultCharset()))
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
}
Anonymous user