Last active
July 18, 2017 02:32
-
-
Save 1RedOne/fbcfde8b17543ae4f14bc605b0e332e8 to your computer and use it in GitHub Desktop.
GetStats.Exe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Net; | |
using System.Text; | |
using System.Web; | |
namespace Examples.System.Ham | |
{ | |
public class WebRequestGetExample | |
{ | |
public static void Main() | |
{ | |
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://public-api.wordpress.com/rest/v1.1/sites/56752040/stats/summary/?fields=views&period=year&num=5"); | |
request.Headers["Authorization"] = "Bearer YourKeyHere"; | |
string foxGreet =@" | |
/^._ | |
,___,--~~~~--' /'~ FoxDeploy Traffic Checking App! | |
`~--~\ )___,)/ ' | |
(/\\_(/\\_ Let's check the stats! | |
"; | |
Console.WriteLine(foxGreet); | |
request.Credentials = CredentialCache.DefaultCredentials; | |
// Get the response. | |
WebResponse response = request.GetResponse(); | |
// Display the status. | |
Console.WriteLine("HTTP Status Code:"+((HttpWebResponse)response).StatusDescription); | |
// Get the stream containing content returned by the server. | |
Stream dataStream = response.GetResponseStream(); | |
// Open the stream using a StreamReader for easy access. | |
StreamReader reader = new StreamReader(dataStream); | |
// Read the content. | |
string responseFromServer = reader.ReadToEnd(); | |
// Display the content. | |
Console.WriteLine(responseFromServer); | |
// Clean up the streams and the response. | |
reader.Close(); | |
response.Close(); | |
Console.WriteLine("Press any key to exit."); | |
Console.ReadKey(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
using System; | |
using System.IO; | |
using System.Net; | |
using System.Text; | |
using System.Web; | |
namespace Examples.System.Ham | |
{ | |
public class WebRequestGetExample | |
{ | |
public static void Main() | |
{ | |
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://public-api.wordpress.com/rest/v1.1/sites/56752040/stats/summary/?fields=views&period=year&num=5"); | |
request.Headers["Authorization"] = "Bearer YourKeyHere"; | |
string foxGreet =@" | |
/^._ | |
,___,--~~~~--' /'~ FoxDeploy Traffic Checking App! | |
`~--~\ )___,)/ ' | |
(/\\_(/\\_ Let's check the stats! | |
"; | |
Console.WriteLine(foxGreet); | |
request.Credentials = CredentialCache.DefaultCredentials; | |
// Get the response. | |
WebResponse response = request.GetResponse(); | |
// Display the status. | |
Console.WriteLine("HTTP Status Code:"+((HttpWebResponse)response).StatusDescription); | |
// Get the stream containing content returned by the server. | |
Stream dataStream = response.GetResponseStream(); | |
// Open the stream using a StreamReader for easy access. | |
StreamReader reader = new StreamReader(dataStream); | |
// Read the content. | |
string responseFromServer = reader.ReadToEnd(); | |
// Display the content. | |
Console.WriteLine(responseFromServer); | |
// Clean up the streams and the response. | |
JObject Stats = JObject.Parse(responseFromServer); | |
Console.WriteLine(Stats.SelectToken("views")); | |
reader.Close(); | |
response.Close(); | |
Console.WriteLine("Press any key to exit."); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment