[英]Angular 7 Unable to get http headers
I trying to do some scraping without python, just a simple http get request from web angular app, the problem is the response, I need gain access to the headers, to get the csrftoken header. 我试图在不使用python的情况下进行一些抓取,只是从web angular应用程序获取一个简单的http get请求,问题是响应,我需要获得对标头的访问权限,才能获取csrftoken标头。
error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (http://localhost:4200/vendor.
Code: 码:
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
});
Your server need to expose Access-Control-Expose-Headers
header to get access to one that you need from js. 您的服务器需要公开Access-Control-Expose-Headers
标头,以便从js访问您需要的标头。
If your response is not a valid json then try using observe property ( observe: 'response'
) on request to prevent angular to parse it as json 如果您的响应不是有效的json,请尝试在请求时使用observe属性( observe: 'response'
),以防止将其解析为json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.