Angular 上的 HTTP headers 5
HTTP headers on Angular 5
我是新手,我认为这个问题对你来说很简单,但请帮忙。
我需要在加载页面上发出 http 请求,它正在运行,但我的查询被消息
阻止了
Cross-Origin Request Blocked: The Same Origin Policy disallows reading
the remote resource at
http://localhost:9999/.
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
有我的 Angular 代码:
export class AppComponent implements OnInit {
public apiURL:string = 'http://localhost:9999/';
public logged: boolean;
response: any;
constructor(private elementRef:ElementRef, private http:Http) {
this.logged = this.elementRef.nativeElement.getAttribute('auth');
}
ngOnInit() {
this.checkLogin()
}
checkLogin() {
this.response = this.http.post(this.apiURL, {"search": "search"}, ).map(res => res.json()).subscribe(data => {console.log(data);});
}
}
我已经尝试了很多变体..但没有人不适合我...有人可以提供解决它的小例子吗...拜托...
这是服务器而非客户端的问题。作为安全措施,您的浏览器阻止您调用其他主机。如果您有权访问服务器,则需要添加:
Access-Control-Allow-Origin: *
否则您将需要一个代理来调用服务器
参见:Origin is not allowed by Access-Control-Allow-Origin
我是新手,我认为这个问题对你来说很简单,但请帮忙。
我需要在加载页面上发出 http 请求,它正在运行,但我的查询被消息
阻止了Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9999/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
有我的 Angular 代码:
export class AppComponent implements OnInit {
public apiURL:string = 'http://localhost:9999/';
public logged: boolean;
response: any;
constructor(private elementRef:ElementRef, private http:Http) {
this.logged = this.elementRef.nativeElement.getAttribute('auth');
}
ngOnInit() {
this.checkLogin()
}
checkLogin() {
this.response = this.http.post(this.apiURL, {"search": "search"}, ).map(res => res.json()).subscribe(data => {console.log(data);});
}
}
我已经尝试了很多变体..但没有人不适合我...有人可以提供解决它的小例子吗...拜托...
这是服务器而非客户端的问题。作为安全措施,您的浏览器阻止您调用其他主机。如果您有权访问服务器,则需要添加:
Access-Control-Allow-Origin: *
否则您将需要一个代理来调用服务器
参见:Origin is not allowed by Access-Control-Allow-Origin