Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a Angular 7 Application with .Net core 2.1, once the application is publish it cannot reach the API, which means no calls can be made, but before i published the application everything worked fine.
What could be the problem and how can i fix this?

Example of a call in my code that checks if the API is accessible:
(this is the first call in my application)
let availabilityHTTPCall = this.http.get("/v1/CheckAvailability");
    availabilityHTTPCall.subscribe(
      (result: boolean) => {
        this._webApiUnavalable = result;
        this.wizardOpen = true;
        console.log("HTTP Call returned data without error!", result);
      },
      (error) => {
        console.log("HTTP Call returned an error!", error);
        this._webApiUnavalable = false;
      },
      () => {
        console.log("HTTP Call complete!");
        this.PlacesOfService();
        this.LoadPhCodes();
      }
    );


What the API looks like in the controller:
[HttpGet]
     [Route("CheckAvailability")]
     public Boolean CheckAvailability()
     {
         return true;
     }


The error i get from my call:
"Http failure during parsing for http://localhost/"

"Unexpected token < in JSON at position 0"


What I have tried:

i have tried to insert a hashtag in-front of my URL of my API call which did not work, since this worked for fixing the reloading of my pages once published.
Posted
Updated 31-Jan-19 23:21pm
v3
Comments
CHill60 1-Feb-19 4:35am    
Without any real details to go on all I can say is … is the "API" installed on the server that is hosting your application. It probably worked before publishing because you have it installed on your own machine
Ashley01 1-Feb-19 4:48am    
Yes it is installed. I'm using IIS express(don't know if it will help)
Wastedtalent 1-Feb-19 4:52am    
Have you tried writing the calls, urls and error messages to the console to get a better indication of what is being called and the response being returned?
Ashley01 1-Feb-19 5:15am    
i updated my Question with a example of my code and the error i get
Richard Deeming 4-Feb-19 13:44pm    
"Unexpected token < in JSON at position 0"
Sounds like IIS is returning an HTML page instead of the expected JSON. Try using the network tab in your browser's developer tools to examine the request and response to see if that gives you any clues.

this.http.get("/v1/CheckAvailability")

Is your API deployed in the root folder of your IIS site?

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