The problem is fairly simple: I am making a request like I have always been doing up until now from my client (angular) to my .net API (3.1). The API is correctly requested and the answer is correctly sent.Yet, when it arrives on my client, the response is null. How is that?
Server side:
[HttpPost][Route("api/XXXXXXXX")][RequestSizeLimit(4_000_000_000)][Microsoft.AspNetCore.Cors.EnableCors]public string JsonFilterResponse([FromBody] JsonElement jsonresult){ try { var json = System.Text.Json.JsonSerializer.Serialize(jsonresult); if (json != null) { var savepath = ".//JsonResponses//"; Random rnd = new Random(); var id = rnd.Next().ToString(); var filePath = Path.Combine(savepath, id); System.IO.File.WriteAllText(filePath, json); // return job complete Response.Body.Flush(); // http response Ok(); return id; // server response --> the id of the file created } else { NotFound(); return null; } } catch (Exception) { StatusCode(500, "Internal server error"); return null; }}
Client side:
public uploadjsonresponse(file, apiname, filename, end, appcomponent, secondapiname) { let headers = new HttpHeaders({'Content-Type': 'application/json','Access-Control-Allow-Origin': '*', }); return this.httpClient.post(this.SERVER_URL + apiname, file, {headers: headers}).pipe(map(res => { appcomponent.filemapper.push(filename +";;;" + res); console.log(appcomponent.filemapper[appcomponent.filemapper.length-1]); if (end) // callback appcomponent.requestmapping(secondapiname, end, this); })); }
The problem is that "res" comes back null client side. Yet, it is being correctly returned by the server (return id). Any ideas as to why that might be?