javascript - Angular 2: HTTP Post Request with URL parameters and body type parameter -


i trying make http post request angular 2 below.

saveuserselection() {     var json = json.stringify({access_token: localstorage.getitem('access_token')});     var params = 'json=' + json;     var headers = new headers();     headers.append({ 'content-type': 'application/json' });      return this.http         .post('http://localhost:8080/user/selection', params, { headers: headers })         .map(res => res.json()); } 

but getting error below.

angular2.dev.js:23877 exception: error during evaluation of "ngsubmit" original exception: syntaxerror: failed execute 'setrequestheader' on 'xmlhttprequest': '[object object]' not valid http header field name. 

does have idea what's wrong code ? , how can create http post request parsing body type parameter ?

this should want:

headers.append('content-type', 'application/json' ); headers.append('access_token', localstorage.getitem('access_token')); 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -