Angular 4 Http POST not working

前端 未结 4 1795
天命终不由人
天命终不由人 2021-02-09 14:19

I hope everyone is doing great. I\'ve recently started working with angular 4.4, i\'ve been trying to post data to my api server, but unfortunately it\'s not working. I\'ve spen

4条回答
  •  离开以前
    2021-02-09 14:42

    import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs';

    saveGame(route,game):Observable{
    
      let json = JSON.stringify(game);
            let params = 'json=' + json;
    
      let headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded');
      return this.http.post(this.URL + route, params, { headers: headers });
    
    }
    

提交回复
热议问题