Im trying to get data from a service using POST request. But I cant change the headers (TS wont compile) or content type. I get this error in console:
status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Content type 'text/plain' not supported"
Below is my component code.
import { Component, OnInit } from '@angular/core';
import { Http, Headers, Response, URLSearchParams } from '@angular/http';
import { HttpClient } from '@angular/common/http';
import 'rxjs/add/operator/map';
@Component({
selector: 'app-search',
templateUrl: './search.component.html',
styleUrls: ['./search.component.css']
})
export class SearchComponent implements OnInit {
searchValue: any = '';
constructor(private http: HttpClient) { }
getData() {
this.http.post('MY URL',
JSON.stringify({
"q": "Achmea"
}))
.subscribe(
data => {
alert('ok');
console.log(data);
}
)
NB: Used the code snippet because the formatting wouldnt let me post as pre.
Using latest angular 4 version. Also server should be correctly configured, accepting only json data. I tried the examples from Angular docs but none of them worked.
Anyone have any idea how to get it working?? Thanks in advance.