我正在使用Angular 5 HttpClient,尝试从提供json数据和HTML的页面(Spotify auth)获取HTML响应。
当我使用curl时,我得到了预期的HTML和json负载。但是,无论我用HttpClient尝试什么,我只能得到json,这在这种情况下没有帮助。我想要获取HTML。我已经验证我的标头在命令行curl和HttpClient之间完全相同。
curl -vvv https://accounts.spotify.com/authorize/?client_id=xxxxxxxxxxxxxxx81ad8fc&response_type=code&redirect_uri=http://reaver.xxxxxx.com:4200/callback&state=34fFs29kd09
<!DOCTYPE html>
<html ng-app="accounts" ng-csp>
<head>
<meta charset="utf-8">
<title ng-bind="(title && (title | localize) + ' - ') + 'Spotify'">Spotify</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<base href="/">
<link href="https://d2d1dxiu3v1f2i.cloudfront.net/a4a5157/css/index.css" media="screen" rel="stylesheet">
<script async defer src="https://www.google.com/recaptcha/api.js"></script>
<script async defer src="https://d2d1dxiu3v1f2i.cloudfront.net/a4a5157/js/index.js" sp-bootstrap></script>
<meta ng-non-bindable sp-bootstrap-data='{"client":{"name":"Playlist Reaver"},"country":"US","useCaptcha":false,"locales":["*"],"BON":["0","0",-795429514]}'>
</head>
<body ng-view></body>
</html>
这个负载的这部分是我能从HttpClient获得的全部内容。
{"client":{"name":"Playlist Reaver"},"country":"US","useCaptcha":false,"locales":["*"],"BON":["0","0",-795429514]}
通常我会说很好,但我真的需要访问HTML。
如何从包含JSON数据和HTML的响应中获取原始HTML?
我的get调用看起来像这样:
return this.http.get(this.apiGeneric, { params: params, observe: 'response'});
额外信息:我的http标头似乎没有被添加。我已经进行了如下更改,但在http请求标头中没有看到XFF标头。
// function returns Observable UserResponse object
getUrl() {
this.httpHeaders = new HttpHeaders();
//.set('Content-Type'
this.httpHeaders.set('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8');
this.httpHeaders.set('XFF', 'testing123');
let params = new HttpParams();
const params = new HttpParams()
.set('client_id', this.clientId)
.set('response_type', 'code')
.set('redirect_uri', this.redirectUri)
console.log(params);
return this.http.get(this.apiGeneric, { headers: this.httpHeaders, params: params, observe: 'response' });
}