When using Postman, the correct response is received with the following JSON in the body:
{
"cpu": {
"filters": [
]
}
}
However, when I make a POST request in my Angular 2 service, the response seems to be empty. Here is the service code:
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions, Response } from '@angular/http';
import { BaseService } from './base.service';
import { Observable } from 'rxjs/Observable';
import { Cpu } from '../entities/cpu';
import { PostObject } from '../entities/post-object';
import { CPU } from '../datasource/database-data';
import 'rxjs/add/operator/map';
@Injectable()
export class CpuService extends BaseService {
postObject: PostObject;
constructor(private http: Http) {
super();
}
getCpus(): void {
this.postObject = new PostObject();
console.log(JSON.stringify(this.postObject));
this.http.post(this.getUrl('/searchCPU'), JSON.stringify(this.postObject))
.subscribe((result: any) =>
console.log(result);
return result
});
}
}`
The structure of the PostObject class is as follows:
export class PostObject {
cpu: {
filters: string[]
}
}
Oddly enough, when logging the postObject object, it appears to be empty. Could it be a problem with
this.postObject = new PostObject();
?