我正在尝试将AirBNB的共享日历添加到Angular 6应用中。我根本无法使它正常工作!如果我从“邮递员”中调用URL,则不会有任何问题,值会返回。如果我在Web浏览器中输入URL,它将下载文件。只是无法获得Angular 6来获取文件。
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
// import {RequestOptions, Request, Headers } from '@angular/http';
import { Component } from '@angular/core';
import { HttpClient, HttpHeaders, HttpErrorResponse } from
'@angular/common/http';
@Component({
selector: 'my-app',
template: 'look at the console <br /> Resposne: {{data}}'
})
export class AppComponent {
data: any
constructor(
private http: HttpClient
){
// let requestOptions = new RequestOptions({ headers:null, withCredentials:
// true });
let getHeaders: HttpHeaders = new HttpHeaders({
'Content-Type': 'text'
});
this.http.get('https://www.airbnb.co.uk/calendar/ical/XXXXX.ics?s=XYZ', { headers: getHeaders})
.subscribe(data =>
this.data = data
)
}
}
@NgModule({
imports: [ BrowserModule, FormsModule, HttpClientModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }