为懒人提供无限可能,生命不息,code不止
作者: whooyun发表于: 2024-11-28 00:08
fetch('http://your-api-endpoint.com/api/some-endpoint', { method: 'GET', headers: { 'Origin': 'http://example.com', 'Content-Type': 'application/json' } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error));
如果接口允许跨域,响应会正常返回。 如果接口不允许跨域,控制台会显示类似以下的错误:
Access to fetch at 'http://your-api-endpoint.com/api/some-endpoint' from origin 'http://example.com' has been blocked by CORS policy.