Rest Angular 2 http post返回200,但未返回响应

Rest Angular 2 http post返回200,但未返回响应,rest,angular,angular2-http,Rest,Angular,Angular2 Http,我的http调用返回200,但未捕获响应订阅中的我的代码未被命中。当我在postman中测试时,API正在返回数据。这是我的密码 getToken(authcode: string) { var data = 'client_id=InspectWebApp_client&code=' + authcode + '&redirect_uri=http://localhost:3000&grant_type=authorization_code';

我的http调用返回200,但未捕获响应订阅中的我的代码未被命中。当我在postman中测试时,API正在返回数据。这是我的密码

getToken(authcode: string) {

        var data = 'client_id=InspectWebApp_client&code=' + authcode + '&redirect_uri=http://localhost:3000&grant_type=authorization_code';
        let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
        let options = new RequestOptions({ headers: headers });
        this.http.post('https://fedloginqa.test.com/as/token.oauth2', data, options)
            .subscribe((res: Response) => {

                var resultsToken = res.json();
               localStorage.setItem("access_token",resultsToken.access_token)
                //return this.inspections;
            })

    }

我也面临着同样的问题。这个问题是通过使用观测值上的映射函数来解决的。以下是我的实现:

login(Username:string, Password:string) : Observable<Response>{
    let headers = new Headers();
    headers.append("Authorization", "Basic " + btoa(Username + ":" + Password)); 
    headers.append("Content-Type", "application/x-www-form-urlencoded");
    return this._http.post(this._baseUrl+"auth/login", " " , {headers: headers}  )
        .map((response: Response) => {
            return response;     
        }).catch(this.handleError);
}
login(用户名:string,密码:string):可观察{
let headers=新的headers();
headers.append(“授权”、“基本”+btoa(用户名+:“+密码));
headers.append(“内容类型”、“应用程序/x-www-form-urlencoded”);
返回此。_http.post(此。_baseUrl+“auth/login”、“”、{headers:headers})
.map((响应:响应)=>{
返回响应;
}).接住(这个.把手错误);
}
这里handleError是一个用于捕获生成的例外的函数。这是login.service.ts中的一个函数,用于向api发送用户名和密码以获取数据。您可以看到,我正在从该服务中的map函数返回响应。现在,这个返回的响应可以通过以下方式在subscribe函数中捕获:

this._loginService.login(this.username, this.password)  
        .subscribe(
            (response) => {
                //Here you can map the response to a type.
                this.apiResult = <IUser>response.json();
            },
            (err) => {
                //Here you can catch the error
            },
            () => {this.router.navigate(['home'])}
        );
this.\u loginService.login(this.username,this.password)
.订阅(
(回应)=>{
//在这里,您可以将响应映射到类型。
this.apireult=response.json();
},
(错误)=>{
//在这里您可以捕捉到错误
},
()=>{this.router.navigate(['home'])}
);