@Sidharth_1999 wrote:
I’m trying to make a POST request to a server I’ve created. But when I run the application, I get the error :
" Unexpected token L in JSON at position 0"This is the code I’m using:
import { Http, Headers} from '@angular/http'; import 'rxjs/add/operator/map'; export class MyClass { constructor(public http : Http){ let headers = new Headers(); headers.append('Content-Type', 'application/json'); let body = { message : "Do you hear me?" }; this.http.post('https://myserverurl', JSON.stringify(body), {headers:headers}) .map(res=>res.json()) .subscribe((data)=>{ console.log(data); }); } }
Appreciate any help anyone has to offer. Thanks !
Posts: 2
Participants: 2