У меня есть API отдыха в моем приложении Spring Boot:
@CrossOrigin
@GetMapping()
public String getText(@RequestHeader(value = "token") String token)
{
if (token == "1") {
return "Hello world";
}
return "511 ";
}
И у меня JS Ajax запрос на мой пользовательский интерфейс:
<script type="text/javascript">
function login() {
const url = 'http://localhost:8085/api';
const otherPram= {
headers: {
'Content-Type': 'application/json',
'token': 'test'
},
method:"GET"
}
fetch(url,otherPram).then(res=>{console.log(res)})
}
</script>
И я хочу напечатать в консоли мой тип возврата "Hello world".