Skip to content

Instantly share code, notes, and snippets.

@1RedOne
Last active July 18, 2017 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1RedOne/fbcfde8b17543ae4f14bc605b0e332e8 to your computer and use it in GitHub Desktop.
Save 1RedOne/fbcfde8b17543ae4f14bc605b0e332e8 to your computer and use it in GitHub Desktop.
GetStats.Exe
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();
}
}
}
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