using System; using System.Net; namespace Example { class Program { static void Main(string[] args) { // Create a WebRequest instance. WebRequest request = WebRequest.Create("https://jsonplaceholder.typicode.com/posts"); // Set the request method. request.Method = "GET"; // Make the request. HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Check the response status code. int statusCode = response.StatusCode; if (statusCode != HttpStatusCode.OK) { throw new Exception("The request failed with status code " + statusCode); } // Get the response content. string content = response.InputStream.ReadToEnd(); // Display the response content. Console.WriteLine(content); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter