Mohsin Arif

Mohsin Arif

  • 295
  • 6k
  • 137.8k

API show 400 Bad Request

Dec 31 2019 6:45 AM
hello guys 
is there any issue in this code , because i m getting 400 bad request error,
  1. public async Task<ActionResult> Index()  
  2.       {  
  3.           List<ModelHome> EmpInfo = new List<ModelHome>();  
  4.   
  5.           using (var client = new HttpClient())  
  6.           {  
  7.               //Passing service base url  
  8.               client.BaseAddress = new Uri(Baseurl);  
  9.   
  10.               client.DefaultRequestHeaders.Clear();  
  11.               //Define request data format  
  12.               client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));  
  13.               
  14.               client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);  
  15.               client.DefaultRequestHeaders.Add("Access-Key", AccessKey);  
  16.                 
  17.   
  18.               //Sending request to find web api REST service resource GetAllEmployees using HttpClient  
  19.               HttpResponseMessage Res = await client.GetAsync("api/Fee/GetDetail?challan_number=4780415&branchCode=24&organizationUserId=445");  
  20.                 
  21.               //Checking the response is successful or not which is sent using HttpClient  
  22.               if (Res.IsSuccessStatusCode)  
  23.               {  
  24.                   //Storing the response details recieved from web api   
  25.                   var EmpResponse = Res.Content.ReadAsStringAsync().Result;  
  26.   
  27.                   //Deserializing the response recieved from web api and storing into the Employee list  
  28.                   EmpInfo = JsonConvert.DeserializeObject<List<ModelHome>>(EmpResponse);  
  29.   
  30.               }  
  31.               //returning the employee list to view  
  32.               return View(EmpInfo);  
  33.           }  
  34.       }  
 

Answers (2)