Angular 7无法获取http头

Angular 7无法获取http头,angular,Angular,我试图在没有python的情况下进行一些刮取,只是来自web angular app的一个简单http get请求,问题是响应,我需要获得对头的访问权,以获取csrftoken头 error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (http://localhost:4200/vendor. 错误:Sy

我试图在没有python的情况下进行一些刮取,只是来自web angular app的一个简单http get请求,问题是响应,我需要获得对头的访问权,以获取csrftoken

error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (http://localhost:4200/vendor.
错误:SyntaxError:XMLHttpRequest.onLoad的JSON.parse()位置0处JSON中的意外标记(http://localhost:4200/vendor.
代码:

const headers=new-HttpHeaders().set('Content-Type','text/html;charset=utf-8');
const r=this.http.request('GET','https://www.example.com', {
标题:标题
});

您的服务器需要暴露
访问控制暴露头文件
头文件才能从js访问您需要的文件


如果您的响应不是有效的json,请尝试使用observe属性(
observe:'response'
)在请求时,为了防止angular将其解析为json

可能会重复使用浏览器查看实际返回的内容,可能是它的xml或html,而不是json。是的,我尝试请求一个html页面,仅用于提取标题,然后使用该数据,我将查找包含我所需数据的端点。使用CORS主题,我将我目前正在使用一个变通方法,chrome的一些插件,另一部分是我设置了这个选项,我仍然将响应作为JSON处理。我也遵循了这个指南:observer和responseType属性的组合完成了这个技巧!是的,正如你提到的,我需要为get ac设置访问控制公开头从web客户端访问顶级标题,但在我的示例中,主体中有一个定义了csrftoken的meta标记,这对我来说非常有用!非常感谢您帮助我找到解决方案!
const headers = new HttpHeaders().set('Content-Type', 'text/html; charset=utf-8');

const r = this.http.request<HttpResponse<Object>>('GET', 'https://www.example.com', {
  headers: headers
});