# Http Post not working

**URL:** <https://forum.ionicframework.com/t/http-post-not-working/68248>\
**Category:** ionic-v1\
**Created:** [October 26, 2016, 8:23am UTC](https://forum.ionicframework.com/t/http-post-not-working/68248 "2016-10-26T08:23:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anicacute09](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anicacute09/32/113162_2.png) [@anicacute09](https://forum.ionicframework.com/u/anicacute09)\
**Post date:** [October 26, 2016, 8:23am UTC](https://forum.ionicframework.com/t/http-post-not-working/68248/1 "2016-10-26T08:23:22Z")

</div>

Hi guys, I am doing an app with http request. I already have a Rest Api for POST/GET and as I use the get i works already. Now my problem is the post method, if I use test app for my post api(postman) it works but when I use it in my ionic app it always return to me something wrong with posting data… Hope you help me with this one.

Here is my code in my Http Post method :

```
$http.post("url(host)", 
          { data: { 
            first_name: $scope.data1.fname,
            last_name: $scope.data1.lname,
            username: $scope.data1.email,
            password: $scope.data1.pass,
            skype_id: $scope.data1.skype,
            location_address: $scope.data1.city,
            gender: $scope.data1.gender,
            birthday: $scope.data1.birthday,
            heading: $scope.data2.heading,
            about: $scope.data2.descriptions,
            marital_status: $scope.data2.status,
            occupation: $scope.data2.work,
            height: $scope.data2.uheight,
            hair_color: $scope.data2.uhair,
            body_type: $scope.data2.ubody,
            nationality: $scope.data2.unation,
            ethnicity: $scope.data2.uethni,
            english_ability: $scope.data2.uenglish,
            spanish_ability: $scope.data2.uspanish,
            living_situation: $scope.data2.uliving,
            willing_to_relocate: $scope.data2.urelocate,
            match_gender: $scope.data2.umatchgender,
            match_min_age: $scope.data2.uagefrom,
            match_max_age: $scope.data2.uageto
          }
        })
          .success(function (response) {
           console.log(response);
          })
          .error(function (response) {
            console.log(response);
            console.log("Error in submitting");
          });
```

---

<div class="post-metadata">

**Author:** ![rgecy](https://avatars.discourse-cdn.com/v4/letter/r/ac8455/32.png) [@rgecy](https://forum.ionicframework.com/u/rgecy)\
**Post date:** [October 26, 2016, 3:25pm UTC](https://forum.ionicframework.com/t/http-post-not-working/68248/2 "2016-10-26T15:25:25Z")

</div>

Try taking the outer brakets {} from around your data object.

```
$http.post("http://dev.colombiandreamdate.com/api/v1/createuser", 
          data: { 
            first_name: $scope.data1.fname,
            last_name: $scope.data1.lname,
            username: $scope.data1.email,
            password: $scope.data1.pass,
            skype_id: $scope.data1.skype,
            location_address: $scope.data1.city,
            gender: $scope.data1.gender,
            birthday: $scope.data1.birthday,
            heading: $scope.data2.heading,
            about: $scope.data2.descriptions,
            marital_status: $scope.data2.status,
            occupation: $scope.data2.work,
            height: $scope.data2.uheight,
            hair_color: $scope.data2.uhair,
            body_type: $scope.data2.ubody,
            nationality: $scope.data2.unation,
            ethnicity: $scope.data2.uethni,
            english_ability: $scope.data2.uenglish,
            spanish_ability: $scope.data2.uspanish,
            living_situation: $scope.data2.uliving,
            willing_to_relocate: $scope.data2.urelocate,
            match_gender: $scope.data2.umatchgender,
            match_min_age: $scope.data2.uagefrom,
            match_max_age: $scope.data2.uageto
        })
          .success(function (response) {
           console.log(response);
          })
          .error(function (response) {
            console.log(response);
            console.log("Error in submitting");
          });
```

---

<div class="post-metadata">

**Author:** ![maxx0r](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/maxx0r/32/91299_2.png) [@maxx0r](https://forum.ionicframework.com/u/maxx0r)\
**Post date:** [October 26, 2016, 3:32pm UTC](https://forum.ionicframework.com/t/http-post-not-working/68248/3 "2016-10-26T15:32:19Z")

</div>

do yourself a favor and construct the object before you pass it to the post. This is bad for maintenance and readability

---

<div class="post-metadata">

**Author:** ![anicacute09](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anicacute09/32/113162_2.png) [@anicacute09](https://forum.ionicframework.com/u/anicacute09)\
**Post date:** [October 27, 2016, 1:16am UTC](https://forum.ionicframework.com/t/http-post-not-working/68248/4 "2016-10-27T01:16:19Z")

</div>

I will make it simple. All I want to do is to make the post work like this code:

```
$http.post("url(host)", 
          { data: {
            first_name: $scope.data1.fname,
            last_name: $scope.data1.lname,
            username: $scope.data1.email,
            password: $scope.data1.pass,
            skype_id: $scope.data1.skype,
            location_address: $scope.data1.city,
            gender: $scope.data1.gender,
            birthday: $scope.data1.birthday
           }
        })
          .success(function (response) {
           console.log(response);
          })
          .error(function (response) {
            console.log(response);
            console.log("Error in submitting");
          });

```

But sadly it is not working…

---

<div class="post-metadata">

**Author:** ![anicacute09](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anicacute09/32/113162_2.png) [@anicacute09](https://forum.ionicframework.com/u/anicacute09)\
**Post date:** [October 27, 2016, 6:40am UTC](https://forum.ionicframework.com/t/http-post-not-working/68248/5 "2016-10-27T06:40:01Z")

</div>

As I study for my problem, I try to get the response (first\_name for example) and it shows me null or blank… I guess that my data are not pass correctly to the api…

---

<div class="post-metadata">

**Author:** ![thesourav](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@thesourav](https://forum.ionicframework.com/u/thesourav)\
**Post date:** [November 16, 2016, 6:07pm UTC](https://forum.ionicframework.com/t/http-post-not-working/68248/6 "2016-11-16T18:07:43Z")

</div>

You can test your API first in POSTMAN or [https://www.hurl.it/](https://www.hurl.it/) and then try in $http.post

---

<div class="post-metadata">

**Author:** ![anicacute09](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anicacute09/32/113162_2.png) [@anicacute09](https://forum.ionicframework.com/u/anicacute09)\
**Post date:** [November 17, 2016, 1:42am UTC](https://forum.ionicframework.com/t/http-post-not-working/68248/7 "2016-11-17T01:42:40Z")

</div>

I already solve this… by letting the header to be in xxx-urlencoded… btw thanks for all the help
