Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/HTTP/Java/http-1.java
Normal file
6
Task/HTTP/Java/http-1.java
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
8
Task/HTTP/Java/http-2.java
Normal file
8
Task/HTTP/Java/http-2.java
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
void printContent(String address) throws URISyntaxException, IOException {
|
||||
URL url = new URI(address).toURL();
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null)
|
||||
System.out.println(line);
|
||||
}
|
||||
}
|
||||
19
Task/HTTP/Java/http-3.java
Normal file
19
Task/HTTP/Java/http-3.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import java.net.URI;
|
||||
import java.net.http.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) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
8
Task/HTTP/Java/http-4.java
Normal file
8
Task/HTTP/Java/http-4.java
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import org.apache.commons.io.IOUtils;
|
||||
import java.net.URL;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
IOUtils.copy(new URL("http://rosettacode.org").openStream(),System.out);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue