Created
October 22, 2012 22:23
-
-
Save sirkirby/3935020 to your computer and use it in GitHub Desktop.
RyanTech VIN Explosion API Vehicle Make w/ Asp.Net
This file contains hidden or 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 Asp.net and Json.NET | |
HttpClient client = new HttpClient(); | |
client.BaseAddress = new Uri("http://vinexplosion.com/api/"); | |
// credentials | |
var byteArray = Encoding.ASCII.GetBytes("username:password"); | |
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); | |
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |
// grab most recent model year | |
var respYears = client.GetAsync("vehicle/years").Result; | |
var json = respYears.Content.ReadAsStringAsync().Result; | |
var years = JArray.Parse(json); | |
var year = years[years.Count - 1]; | |
// now grab the first make in the array for the desired year | |
var respMakes = client.GetAsync("vehicle/makes/?year=" + year).Result; | |
json = respMakes.Content.ReadAsStringAsync().Result; | |
var makes = JArray.Parse(json); | |
var make = makes[0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment