Skip to content

Instantly share code, notes, and snippets.

@1RedOne
Last active Jul 18, 2017
Embed
What would you like to do?
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