Files
curlconverter/fixtures/java_output/get_silent.java
jeayu 2ed1fd3be8 Add generator for Java (#256)
* Add generator for Java

* Add support for Java

* Refactor Java generator

* Decompressing gzip
2021-03-25 20:21:57 -07:00

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);
}
}