Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.IO;
  4. using Newtonsoft.Json;
  5.                    
  6. public class Program
  7. {
  8.     public static void Main()
  9.     {
  10.         dynamic stuff = JsonConvert.DeserializeObject(Get("https://api.spacexdata.com/v3/launches?rocket_id=falcon9&launch_success=false"));
  11.        
  12.         foreach(string ship in stuff[0].ships) {
  13.             dynamic stuff2 = JsonConvert.DeserializeObject(Get("https://api.spacexdata.com/v3/ships/" + ship));
  14.             Console.WriteLine(stuff2.ship_type);
  15.         }
  16.     }
  17.    
  18.     public static string Get(string uri)
  19.     {
  20.         HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
  21.         request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
  22.  
  23.         using(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  24.         using(Stream stream = response.GetResponseStream())
  25.         using(StreamReader reader = new StreamReader(stream))
  26.         {
  27.             return reader.ReadToEnd();
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement