我在角度4中有一个Http Get,但Chrome / Safari与Firefox的身体反应不同
我的要求是:
this.http.get('https://cors-anywhere.herokuapp.com/https://drive.google.com/uc?export=download&id=0B250MRS8iWM0UFRfc3BBaWRfUlU').subscribe(data => {
// Read the result field from the body response.
console.log(data);
});
我的回答:
任何人都可以帮助我吗?或者对这个问题的任何想法?
[更新身体反应:]
+ Safari浏览器:
1 00:00:24,213 - > 00:00:29376 Dịchbởi:Nhung Nhung。
2 00:01:23,835 - > 00:01:24738 Thếnàoreồi?
3 00:01:25,130 - > 00:01:27378 Bàmẹđangàokhóc cònôngchúthìđangcáuầmlên。
4 00:01:28,080 - > 00:01:30495 - Bàấykhôngcóchồngà? - Lydị,mộtnách4con。
5 00:01:31,297 - > 00:01:33143 TôiđoánchắcChaxứđangmuốngiúpthôi。
6 00:01:33,452 - > 00:01:34540 Giúp?
+火狐:
��1
00:00:24,213 - > 00:00:29376
D chb i:Nhung Nhung。
2
00:01:23,835 - > 00:01:24738
Th n ore i?
3
00:01:25,130 - > 00:01:27378
B m angg okh c
c n ngch th ngc u ml n。
4
00:01:28,080 - > 00:01:30495
B ykh ngc ch ng ?
Lyd ,m tn ch4con。
5
00:01:31,297 - > 00:01:33143
T iu nch cChax angmu ngi pth i。
6
00:01:33,452 - > 00:01:34540
GIP?
7
00:01:37,685 - > 00:01:40015
Ch o ngBurke,h ang saungsau
n ichuy nv igi[...]
答案 0 :(得分:0)
根据您的评论,您使用的是旧Http
,您需要执行以下操作:
let url: string = 'https://cors-anywhere.herokuapp.com/https://drive.google.com/uc?export=download&id=0B250MRS8iWM0UFRfc3BBaWRfUlU';
this.http.get(url)
.map((res: Response) => res.json())
.subscribe(data => {
// Read the result field from the body response.
console.log(data);
});
您缺少map方法,该方法将响应映射回json。
更新到新的HttpClientModule:
将以下内容添加到app.module.ts
:
import {HttpClientModule} from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
HttpClientModule,
],
})
export class MyAppModule {}
在* .component.ts中:
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
let url: string = 'https://cors-anywhere.herokuapp.com/https://drive.google.com/uc?export=download&id=0B250MRS8iWM0UFRfc3BBaWRfUlU';
this.http.get<any>(url)
.subscribe((data: any) => {
// Read the result field from the body response.
console.log(data);
});