Skip to content

Commit

Permalink
Ejercicio inicial completado, revisar si se puede optimizar mas o hac…
Browse files Browse the repository at this point in the history
…er de otra manera
  • Loading branch information
simonguzman committed Sep 9, 2024
1 parent 9529223 commit a8722a8
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Roadmap/20 - PETICIONES HTTP/java/simonguzman.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class simonguzman {
public static void main(String[] args) throws IOException{
makeHttpRequest("https://www.google.com/");
}

public static void makeHttpRequest(String url) throws IOException{
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();

con.setRequestMethod("GET");

int responseCode = con.getResponseCode();
if (responseCode == 200) {
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();

System.out.println(response.toString());
}else{
System.out.println("ERROR: "+responseCode);
}
}
}

0 comments on commit a8722a8

Please sign in to comment.