reactjsapihttp-status-code-204

Api call gives 204 from application


I have deployed my react app and .net core api on server. .net core api call works fine when I checked from browser. But when I invoke it from react app it gives 204 no-content. Everything works fine in local.

I have enabled CORS like this

options.AddPolicy(MyAllowSpecificOrigins,
                builder =>
                {
                    builder.WithOrigins("http://serverip:5000",
                            "http://serverip:3000"
}   

api call---

[HttpGet]
    [Route("path/{id}")]
    public async Task<ActionResult<List<myData>>> GetByType(byte id)
    {

      if (IsUserAuthenticated())
            return await _myRepo.GetMyData(id);
        else
            return null;
    }

react call-----

      axios.get('http://ip:5000/api/value1/value2/' + param1, { 
      withCredentials: true })

Appreciate any help !


Solution

  • At the end,it was a silly mistake from my end. I had hardcoded localhost url somewhere in the flow and that was causing CORS issue when accessing from server. Appreciate all the help !