当我从angular 2应用程序发送http post请求时,我收到403禁止错误.下面是form.component.ts和service.ts的代码.
form.component.ts
`import {Component, OnInit} from '@angular/core';
import { RegisterUser} from '../Model/RegisterUser';
import { RegisterService } from
'../Services/RegisterService';
@Component({
selector:'register-user-form',
templateUrl:'/app/Htmls/Register.html',
providers : [RegisterService]
})
export class RegisterUserComponent implements OnInit{
submitted=false;
constructor(private registerUserService : RegisterService ){
}
ngOnInit(){
}
onSubmit(value:RegisterUser){
this.registerUserService.pushUser(value).subscribe(
);
console.log(value) ;
}
}`
Run Code Online (Sandbox Code Playgroud)
以下是service.ts
import { Injectable } from '@angular/core';
import { Headers,Http, Response } from '@angular/http';
import { RegisterUser} from '../Model/RegisterUser';
import 'rxjs/add/operator/map';
@Injectable()
export class RegisterService {
private headers = new Headers({'content-type': 'application/json'}); …Run Code Online (Sandbox Code Playgroud)