I set up an API with the GET method on the server which, by giving it an authorization token and a body in which a code is specified, returns the info of an object with the same code (it's a serial number). I've tried this code (lookFor is my serial number):
getInfoMatricola(matricola: string,_token: string){
fetch(this.url, {
method: 'GET',
headers: {
Authorization: `Bearer ${_token}`
},
body: ` lookFor":"${matricola} `,
})
.then((response) => response.json())
.then((data) => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
}
}`
It's giving me this error in the console log
Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
I've also tried with the http.get<any>(mycode)
, but it doesn't accept a body I think, because of the error it gave me.