Q:

Ionic2 http post performs http get

I am trying to post data using angular http post method like below. However, whenever I perform this, it performs get method instead. Any advice or suggestion would be appreciated.

login() {
    let headers = new Headers();
    headers.append('Content-Type','application/x-www-form-urlencoded');
    let options = new RequestOptions({ headers: headers });
    let data = {
        "id" : this.phoneNumber,
        "uuid": '1234123412341234'
    }
    const body = new URLSearchParams();
    Object.keys(data).forEach(key => {
        body.set(key, data[key]);
    })

    let token = 'a%2FxMRIEsjokCR6vBkmpjh2UBeRKlVxLEiXundnAoqz0%3D';
    var url = '/api/auth/login?origin=driver&access-token='+token;
    this.http.post(url, body.toString(), options).subscribe( data =>{
        console.log(data);
    })
}

I have coded similar thing like below with angular 1.
$scope.login = function(){
    var link = proxy_link+'api/auth/login';

    $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";

    $http({
        method: 'POST',
        url: link,
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        transformRequest: function(obj) {
            var str = [];
            for(var p in obj)
            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
            return str.join("&");
        },
        params: {
            'device': 'android',
        },
        data: {
            id:$scope.data.id,
            pw:$scope.data.pw,
            device_token: localStorage.myPush,
            uuid : localStorage.uuid,
            imei: localStorage.imei
        }
    }).success(function(data){
        // do something
    }).error(function(data){
       // handle error
    });

};

A:

Looking at your angular 1 code, You need to send all parameters in the POST form data and not in url.
Try:
login() {
    let headers = new Headers();
    headers.append('Content-Type','application/x-www-form-urlencoded');
    let options = new RequestOptions({ headers: headers });
    let token = 'a%2FxMRIEsjokCR6vBkmpjh2UBeRKlVxLEiXundnAoqz0%3D';
    //set it here
    let data = {
        "id" : this.phoneNumber,
        "uuid": '1234123412341234',
        "origin":driver,
        "access_token":token
    }
    const body = new URLSearchParams();
    Object.keys(data).forEach(key => {
        body.set(key, data[key]);
    })

    var url = '/api/auth/login';
    this.http.post(url, body, options).subscribe( data =>{
        console.log(data);
    })
}

