mirror of
https://github.com/curlconverter/curlconverter.git
synced 2022-05-22 02:35:29 +03:00
* Add generator for Java * Add support for Java * Refactor Java generator * Decompressing gzip
22 lines
646 B
Java
22 lines
646 B
Java
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
import java.util.Scanner;
|
|
|
|
class Main {
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
URL url = new URL("www.google.com");
|
|
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
|
httpConn.setRequestMethod("GET");
|
|
|
|
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
|
|
? httpConn.getInputStream()
|
|
: httpConn.getErrorStream();
|
|
Scanner s = new Scanner(responseStream).useDelimiter("\\A");
|
|
String response = s.hasNext() ? s.next() : "";
|
|
System.out.println(response);
|
|
}
|
|
}
|