File tree 1 file changed +47
-0
lines changed
Roadmap/20 - PETICIONES HTTP/C#
1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * EJERCICIO:
3
+ * Utilizando un mecanismo de peticiones HTTP de tu lenguaje, realiza
4
+ * una petición a la web que tú quieras, verifica que dicha petición
5
+ * fue exitosa y muestra por consola el contenido de la web.
6
+ *
7
+ * DIFICULTAD EXTRA (opcional):
8
+ * Utilizando la PokéAPI (https://pokeapi.co), crea un programa por
9
+ * terminal al que le puedas solicitar información de un Pokémon concreto
10
+ * utilizando su nombre o número.
11
+ * - Muestra el nombre, id, peso, altura y tipo(s) del Pokémon
12
+ * - Muestra el nombre de su cadena de evoluciones
13
+ * - Muestra los juegos en los que aparece
14
+ * - Controla posibles errores
15
+ */
16
+
17
+ namespace Roadmap
18
+ {
19
+ internal class Reto20
20
+ {
21
+
22
+ static async Task Main ( string [ ] args )
23
+ {
24
+ HttpClient client = new HttpClient ( )
25
+ {
26
+ BaseAddress = new Uri ( "http://jsonplaceholder.typicode.com" )
27
+ } ;
28
+
29
+ await PeticionHttp ( client ) ;
30
+ }
31
+
32
+ private async static Task PeticionHttp ( HttpClient client )
33
+ {
34
+ try
35
+ {
36
+ using HttpResponseMessage response = await client . GetAsync ( "Todos/1" ) ;
37
+ response . EnsureSuccessStatusCode ( ) ;
38
+ string jsonResponse = await response . Content . ReadAsStringAsync ( ) ;
39
+ Console . WriteLine ( jsonResponse ) ;
40
+ }
41
+ catch ( HttpRequestException ex )
42
+ {
43
+ Console . WriteLine ( ex . Message ) ;
44
+ }
45
+ }
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments