How do we convert an object to application/x-www-form-urlencoded in angular 4 -


i trying perform login using post method in angular 4 application requires url , application/x-www-form-urlencoded data(in body not header).

i found function in similar post angularjs doesn't seem work on angular v4

var str = []; (var key in obj) { if (obj.hasownproperty(key)) { str.push(encodeuricomponent(key) + "=" + encodeuricomponent(obj[key]))                   console.log(key + " -> " + obj[key]); }} return str.join("&"); 

angular official documentation have removed link https://angular.io/api/http/baserequestoptions-class , nor supported query-string import available.

i wish know if there's other method or module use.

if want perform application/x-www-form-urlencoded post request , store object in body of request, works.

post(data) {     let options = new defaultrequestoptions();         let params = new urlsearchparams("");          (var key in data) {            if (data.hasownproperty(key)) {               params.append(key, data[key])            }         }          this.http.post('some url', params , options); } 

otherwise, can send data via url directly header options.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -