我是Angular的最新版本的新手。 http.post
似乎无法在我的应用程序中的任何地方工作。我已经尝试了诸如:角度4 http.post不发送或工作
this.http
.post(this.bikesUrl, data, { headers: this.headers })
.toPromise()
.then(res => res.json().data)
.catch(this.handleError);
......或者......
this.http.post(this.config.apiEndpoint+'/authenticate', JSON.stringify({ username: username, password: password }))
.map((response: Response) => {
// login successful if there's a jwt token in the response
let token = response.json() && response.json().token;
if (token) {
// set token property
this.token = token;
// store username and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('currentUser', JSON.stringify({ username: username, token: token }));
// return true to indicate successful login
return true;
} else {
// return false to indicate failed login
return false;
}
}).subscribe(result => {
if (result === true) {
// login successful
this.router.navigate(['/']);
} else {
// login failed
this.error = 'Username or password is incorrect';
this.loading = false;
}
})
......或者......
var json = {var1: 'test'};
var params = 'json='+json;
let headers = new Headers();
headers.append('Content-Type', 'application/json');
http.post("http://example.com/infoarray.php", params, headers).subscribe (re => {
console.log(re)
})
当我在浏览器中运行这是几乎像剧本不在那里。我没有看到检查员的要求。我正在使用Angular CLI
您是否能够缩小它不起作用的部分?就像整个应用程序工作正常,除了'http.post'? – CozyAzure
是的,所有的应用程序的作品。但http.post – LogicDev
你可以告诉我你的API代码吗? –