I've come across numerous discussions about the error I'm experiencing, but none of the solutions seem to apply to my situation. This morning, when I ran my code, I encountered the "Unexpected end of Json Input" error. Interestingly, I hadn't made any changes to my code or updated any packages. Strangely, the same code works perfectly fine on my colleague's computer even though we have identical packages and versions.
The issue arises when I make a request to the server - it responds with a "status 200 ok" message, but the response body is empty as shown in the image below.
https://i.sstatic.net/0SWzr.png
Additional details about the error can be found in this image:
https://i.sstatic.net/z8zmS.png
Below is a snippet of the code causing the error:
console.log(localStorage.getItem("usedURL"));
return new Promise((resolve, reject) => {
let headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/x-www-form-urlencoded');
this.http.post(localStorage.getItem("usedURL")+"/login", JSON.stringify({ "UserName": credentials.email, "Password": credentials.password }), { headers: headers})
.subscribe(res => {
console.log(res);
resolve(res.json());
}, (err) => {
reject(err);
});
});
Despite my efforts to troubleshoot by clearing the cache, deleting node modules, and even copying my colleague's code, the issue persists. I'm starting to think that the problem may not be related to the code itself. Does anyone have any ideas on how I can resolve this issue?
Thanks.