using Microsoft.Extensions.Logging; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1.Mile; internal class BaoruhMile { const string urlFormat = "https://e-bus.baoruh.com/carno/{0}"; public static async Task GetMile(string carNumber, ILogger? logger = null) { try { HttpClient client = new HttpClient(); string url = string.Format(urlFormat, carNumber); var result = await client.GetAsync(url); if (result.IsSuccessStatusCode) { //Stream contentStream = await result.Content.ReadAsStreamAsync(); //var body = await new StreamReader(contentStream).ReadToEndAsync(); var body = await result.Content.ReadAsStringAsync(); JObject jo = JObject.Parse(body); string checkKey = jo.Value("CarNumber");// jo["State"].Value(); if (checkKey == carNumber && jo.ContainsKey("DR_MILE")) { decimal mileage = jo.Value("DR_MILE"); return mileage; } return 1; } } catch (Exception e) { } return -1; } }