如何在JavaScript中获取客户端IP , angularjs2 并限制对其他用户的访问权限。
答案 0 :(得分:0)
简单的Http get请求可以帮助您
constructor(private http: Http) { }
getIp(): Promise<Hero[]> {
return this.http.get(this.heroesUrl)
.toPromise()
.then(response => {
console.log(response);
})
.catch(this.handleError);
}
private handleError(error: any): Promise<any> {
console.error('An error occurred', error);
return Promise.reject(error.message || error);
}
您的回复将是这样的
{
"ip": "xxx.xx.xxx.xxx",
"city": "Chennai",
"region": "Tamil Nadu",
"country": "IN",
"loc": "10.0833,79.2833",
"org": "AS4755 TATA COMM MAINTAINER"
}