Click here to Skip to main content
16,004,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

What I have tried:

Below is my RestSharp Code from ActionResult

C#
var client = new RestClient(Request.Url.GetLeftPart(UriPartial.Authority).ToString());
             var request = new RestRequest("http://domain.co.za/api/student/getBookedSlotHistory", Method.POST);
                request.AddHeader("cache-control", "no-cache");
                request.AddObject(new StudentInput()
                {
                    StudentNumber = "219193029"//UserIdentity.Username()
                });

                var result = client.Execute<StudentBookingHistoryOutput>(request);
                var data = JsonConvert.DeserializeObject<StudentBookingHistoryOutput>(result.Content);


Then below is my APIController
C#
[HttpPost]
        [Route("api/student/getBookedSlotHistory")]
        public async Task<StudentBookingHistoryOutput> GetHistory(StudentInput input)
        {

            return await _studentRepository.GetBookingHistoryData(input);
        }
Posted
Updated 3-May-19 0:14am
Comments
F-ES Sitecore 2-May-19 11:12am    
What is "RestClient"?
Anele Ngqandu 2-May-19 11:18am    
Thats RestSharp http://restsharp.org/. Am using restsharp to call the api
F-ES Sitecore 2-May-19 11:34am    
Look at the documentation to see if there is a way to force it to use no authentication when doing a REST call.
[no name] 2-May-19 16:04pm    
'nbsp' appears to be referring to a non-breaking space that hasn't been properly escaped in the HTML. So, you "might" need to look beyond just your "code".
Anele Ngqandu 3-May-19 1:13am    
I did think about that and done some searching but nothing. I even tried httpclient and still get the same errors.

1 solution

This line solved the problem.
C#
request.UseDefaultCredentials = true;
Thanks guys
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900