using System.Net.Http; using System.Net.Http.Headers; using System.Web; using Newtonsoft.Json; using System.Net; private static void GetCardInformation(string token) { using (var httpClientGet = new HttpClient()) { httpClientGet.BaseAddress = new Uri("https://cdu-test.arcelik.com/CardDataApi/"); httpClientGet.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); var barcode = "TT0167260099161800197700000000001601010403000205020011e147db530000000000"; var responseGet = httpClientGet.GetAsync("api/CardData/GetProductCardData?barcode="+ barcode).Result.Content.ReadAsStringAsync().Result; ReturnModel<CardDataModel> resultObj = JsonConvert.DeserializeObject<ReturnModel<CardDataModel>>(responseGet); if (resultObj.Status == ReturnTypeStatus.Success) { Console.WriteLine("Card found in cloud"); //"Data" attr in "resultObj" provides card informations in your query above. } else if (resultObj.Status == ReturnTypeStatus.NotFound) { //result not found message Console.WriteLine(resultObj.Message); } else if (resultObj.Status == ReturnTypeStatus.Error) { //error message Console.WriteLine(resultObj.Message); } Console.ReadLine(); } }
时间: 2024-02-10 15:33:49 浏览: 156
node-v12.17.0-headers.tar.gz
这段代码是用来获取指定条形码(barcode)商品的信息。它使用了 HttpClient 类库来发送 GET 请求,其中包含访问令牌(access token)和指定的条形码信息。在服务器端验证通过后,会返回一个包含商品信息的 JSON 数据,这里使用了 NewtonSoft.Json 类库来解析 JSON 数据。最后,根据返回的状态码,判断查询结果,并将结果输出到控制台。
阅读全文