Anele Ngqandu

Anele Ngqandu

  • 983
  • 417
  • 25.5k

Why is my API throws an error when using authentication mode

May 2 2019 10:11 AM

Somehow when using Windows mode, I get an Exception Error"Reference to undeclared entity 'nbsp'. Line 69, position 41."" weird. Then when I check the result.Content after executing I get like an html page with errors like 401 - Unauthorized: Access is denied due to invalid credentials. This is an issue that happens on the IIS Server too.

Below is my RestSharp Code from ActionResult
  1. var client = new RestClient(Request.Url.GetLeftPart(UriPartial.Authority).ToString());  
  2.             var request = new RestRequest("http://domain.co.za/api/student/getBookedSlotHistory", Method.POST);  
  3.                request.AddHeader("cache-control""no-cache");  
  4.                request.AddObject(new StudentInput()  
  5.                {  
  6.                    StudentNumber = "219193029"//UserIdentity.Username()  
  7.                });  
  8.   
  9.                var result = client.Execute(request);  
  10.                var data = JsonConvert.DeserializeObject(result.Content);  
Then below is my APIController
  1. [HttpPost]  
  2.        [Route("api/student/getBookedSlotHistory")]  
  3.        public async Task GetHistory(StudentInput input)  
  4.        {  
  5.   
  6.            return await _studentRepository.GetBookingHistoryData(input);  
  7.        }

Answers (3)