ionic native http POST is not sending data to the server












0















I ran into the some problem. POST is not sending data to the server. GET is working fine. Below is my code:-



post(user){
let bodynow = {
"email_id": "aa@gmsd.sdf",
"mobile":"9978897989",
"first_name": "dfdf",
"last_name": "ghgfh",
"user_title":"MS",
"country_code": "91"
}

const url =
"https://www.allevoyage.com/index.php/hotels_android/update_profile";
this.http.setDataSerializer("json");
this.http
.post(url, bodynow,headers)
.then(data => {
console.log(data,data.url);
})
.catch(err => {
console.log(err);
});
}



Following are the version:

cordova-plugin-advanced-http version:-2.0.1

ionic-native/http version:-4.17.0

"cordova-ios": "4.5.5"




I'm getting proper output when i'm using postman, but when i'm using ionic native http it is not sending data to the server and i'm getting status 200, user not exist as result.

Can someone please help me with where I went wrong










share|improve this question





























    0















    I ran into the some problem. POST is not sending data to the server. GET is working fine. Below is my code:-



    post(user){
    let bodynow = {
    "email_id": "aa@gmsd.sdf",
    "mobile":"9978897989",
    "first_name": "dfdf",
    "last_name": "ghgfh",
    "user_title":"MS",
    "country_code": "91"
    }

    const url =
    "https://www.allevoyage.com/index.php/hotels_android/update_profile";
    this.http.setDataSerializer("json");
    this.http
    .post(url, bodynow,headers)
    .then(data => {
    console.log(data,data.url);
    })
    .catch(err => {
    console.log(err);
    });
    }



    Following are the version:

    cordova-plugin-advanced-http version:-2.0.1

    ionic-native/http version:-4.17.0

    "cordova-ios": "4.5.5"




    I'm getting proper output when i'm using postman, but when i'm using ionic native http it is not sending data to the server and i'm getting status 200, user not exist as result.

    Can someone please help me with where I went wrong










    share|improve this question



























      0












      0








      0








      I ran into the some problem. POST is not sending data to the server. GET is working fine. Below is my code:-



      post(user){
      let bodynow = {
      "email_id": "aa@gmsd.sdf",
      "mobile":"9978897989",
      "first_name": "dfdf",
      "last_name": "ghgfh",
      "user_title":"MS",
      "country_code": "91"
      }

      const url =
      "https://www.allevoyage.com/index.php/hotels_android/update_profile";
      this.http.setDataSerializer("json");
      this.http
      .post(url, bodynow,headers)
      .then(data => {
      console.log(data,data.url);
      })
      .catch(err => {
      console.log(err);
      });
      }



      Following are the version:

      cordova-plugin-advanced-http version:-2.0.1

      ionic-native/http version:-4.17.0

      "cordova-ios": "4.5.5"




      I'm getting proper output when i'm using postman, but when i'm using ionic native http it is not sending data to the server and i'm getting status 200, user not exist as result.

      Can someone please help me with where I went wrong










      share|improve this question
















      I ran into the some problem. POST is not sending data to the server. GET is working fine. Below is my code:-



      post(user){
      let bodynow = {
      "email_id": "aa@gmsd.sdf",
      "mobile":"9978897989",
      "first_name": "dfdf",
      "last_name": "ghgfh",
      "user_title":"MS",
      "country_code": "91"
      }

      const url =
      "https://www.allevoyage.com/index.php/hotels_android/update_profile";
      this.http.setDataSerializer("json");
      this.http
      .post(url, bodynow,headers)
      .then(data => {
      console.log(data,data.url);
      })
      .catch(err => {
      console.log(err);
      });
      }



      Following are the version:

      cordova-plugin-advanced-http version:-2.0.1

      ionic-native/http version:-4.17.0

      "cordova-ios": "4.5.5"




      I'm getting proper output when i'm using postman, but when i'm using ionic native http it is not sending data to the server and i'm getting status 200, user not exist as result.

      Can someone please help me with where I went wrong







      cordova ionic-framework ionic-native






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 3:59







      user10549656

















      asked Nov 28 '18 at 3:48









      Asmitha j.sAsmitha j.s

      464




      464
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Try to put this in header "Content-Type": "application/x-www-form-urlencoded"






          share|improve this answer
























          • After putting header also its the same

            – Asmitha j.s
            Nov 28 '18 at 9:11



















          0














          You should try this:



          First Import the map operator:



          import { map } from "rxjs/operators/map";


          Then the following code:



          var headers = new Headers();
          headers.append('Access-Control-Allow-Origin' , '*'); //your origin
          headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT'); //optional
          headers.append('Accept','application/json'); //optional
          headers.append('content-type','application/json'); //set your content-type

          this.http.post("https://www.allevoyage.com/index.php/hotels_android/update_profile" , bodynow, {headers: headers}).pipe(
          map(res => res.json())
          ).subscribe(response => {
          console.log("Response: " + response);
          });





          share|improve this answer
























          • I'm using ionic native http plugin not the angular http

            – Asmitha j.s
            Nov 28 '18 at 9:17











          • Okay otherwise i would highly recommend to use XMLHttpRequest

            – Jonathan
            Nov 28 '18 at 9:19











          • Is there any reason to especially use the native http plugin? Because it would work way more better with a XMLHttpRequest

            – Jonathan
            Nov 28 '18 at 9:25











          • Yes. Because of cors error, i'm using native http

            – Asmitha j.s
            Nov 28 '18 at 9:42











          • You will always get a cors error when you dont set Request headers. Doesnt matter what you are using to do the post request

            – Jonathan
            Nov 28 '18 at 9:46











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53511831%2fionic-native-http-post-is-not-sending-data-to-the-server%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Try to put this in header "Content-Type": "application/x-www-form-urlencoded"






          share|improve this answer
























          • After putting header also its the same

            – Asmitha j.s
            Nov 28 '18 at 9:11
















          0














          Try to put this in header "Content-Type": "application/x-www-form-urlencoded"






          share|improve this answer
























          • After putting header also its the same

            – Asmitha j.s
            Nov 28 '18 at 9:11














          0












          0








          0







          Try to put this in header "Content-Type": "application/x-www-form-urlencoded"






          share|improve this answer













          Try to put this in header "Content-Type": "application/x-www-form-urlencoded"







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 '18 at 4:23









          suniel kalwanisuniel kalwani

          234318




          234318













          • After putting header also its the same

            – Asmitha j.s
            Nov 28 '18 at 9:11



















          • After putting header also its the same

            – Asmitha j.s
            Nov 28 '18 at 9:11

















          After putting header also its the same

          – Asmitha j.s
          Nov 28 '18 at 9:11





          After putting header also its the same

          – Asmitha j.s
          Nov 28 '18 at 9:11













          0














          You should try this:



          First Import the map operator:



          import { map } from "rxjs/operators/map";


          Then the following code:



          var headers = new Headers();
          headers.append('Access-Control-Allow-Origin' , '*'); //your origin
          headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT'); //optional
          headers.append('Accept','application/json'); //optional
          headers.append('content-type','application/json'); //set your content-type

          this.http.post("https://www.allevoyage.com/index.php/hotels_android/update_profile" , bodynow, {headers: headers}).pipe(
          map(res => res.json())
          ).subscribe(response => {
          console.log("Response: " + response);
          });





          share|improve this answer
























          • I'm using ionic native http plugin not the angular http

            – Asmitha j.s
            Nov 28 '18 at 9:17











          • Okay otherwise i would highly recommend to use XMLHttpRequest

            – Jonathan
            Nov 28 '18 at 9:19











          • Is there any reason to especially use the native http plugin? Because it would work way more better with a XMLHttpRequest

            – Jonathan
            Nov 28 '18 at 9:25











          • Yes. Because of cors error, i'm using native http

            – Asmitha j.s
            Nov 28 '18 at 9:42











          • You will always get a cors error when you dont set Request headers. Doesnt matter what you are using to do the post request

            – Jonathan
            Nov 28 '18 at 9:46
















          0














          You should try this:



          First Import the map operator:



          import { map } from "rxjs/operators/map";


          Then the following code:



          var headers = new Headers();
          headers.append('Access-Control-Allow-Origin' , '*'); //your origin
          headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT'); //optional
          headers.append('Accept','application/json'); //optional
          headers.append('content-type','application/json'); //set your content-type

          this.http.post("https://www.allevoyage.com/index.php/hotels_android/update_profile" , bodynow, {headers: headers}).pipe(
          map(res => res.json())
          ).subscribe(response => {
          console.log("Response: " + response);
          });





          share|improve this answer
























          • I'm using ionic native http plugin not the angular http

            – Asmitha j.s
            Nov 28 '18 at 9:17











          • Okay otherwise i would highly recommend to use XMLHttpRequest

            – Jonathan
            Nov 28 '18 at 9:19











          • Is there any reason to especially use the native http plugin? Because it would work way more better with a XMLHttpRequest

            – Jonathan
            Nov 28 '18 at 9:25











          • Yes. Because of cors error, i'm using native http

            – Asmitha j.s
            Nov 28 '18 at 9:42











          • You will always get a cors error when you dont set Request headers. Doesnt matter what you are using to do the post request

            – Jonathan
            Nov 28 '18 at 9:46














          0












          0








          0







          You should try this:



          First Import the map operator:



          import { map } from "rxjs/operators/map";


          Then the following code:



          var headers = new Headers();
          headers.append('Access-Control-Allow-Origin' , '*'); //your origin
          headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT'); //optional
          headers.append('Accept','application/json'); //optional
          headers.append('content-type','application/json'); //set your content-type

          this.http.post("https://www.allevoyage.com/index.php/hotels_android/update_profile" , bodynow, {headers: headers}).pipe(
          map(res => res.json())
          ).subscribe(response => {
          console.log("Response: " + response);
          });





          share|improve this answer













          You should try this:



          First Import the map operator:



          import { map } from "rxjs/operators/map";


          Then the following code:



          var headers = new Headers();
          headers.append('Access-Control-Allow-Origin' , '*'); //your origin
          headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT'); //optional
          headers.append('Accept','application/json'); //optional
          headers.append('content-type','application/json'); //set your content-type

          this.http.post("https://www.allevoyage.com/index.php/hotels_android/update_profile" , bodynow, {headers: headers}).pipe(
          map(res => res.json())
          ).subscribe(response => {
          console.log("Response: " + response);
          });






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 '18 at 6:35









          JonathanJonathan

          1028




          1028













          • I'm using ionic native http plugin not the angular http

            – Asmitha j.s
            Nov 28 '18 at 9:17











          • Okay otherwise i would highly recommend to use XMLHttpRequest

            – Jonathan
            Nov 28 '18 at 9:19











          • Is there any reason to especially use the native http plugin? Because it would work way more better with a XMLHttpRequest

            – Jonathan
            Nov 28 '18 at 9:25











          • Yes. Because of cors error, i'm using native http

            – Asmitha j.s
            Nov 28 '18 at 9:42











          • You will always get a cors error when you dont set Request headers. Doesnt matter what you are using to do the post request

            – Jonathan
            Nov 28 '18 at 9:46



















          • I'm using ionic native http plugin not the angular http

            – Asmitha j.s
            Nov 28 '18 at 9:17











          • Okay otherwise i would highly recommend to use XMLHttpRequest

            – Jonathan
            Nov 28 '18 at 9:19











          • Is there any reason to especially use the native http plugin? Because it would work way more better with a XMLHttpRequest

            – Jonathan
            Nov 28 '18 at 9:25











          • Yes. Because of cors error, i'm using native http

            – Asmitha j.s
            Nov 28 '18 at 9:42











          • You will always get a cors error when you dont set Request headers. Doesnt matter what you are using to do the post request

            – Jonathan
            Nov 28 '18 at 9:46

















          I'm using ionic native http plugin not the angular http

          – Asmitha j.s
          Nov 28 '18 at 9:17





          I'm using ionic native http plugin not the angular http

          – Asmitha j.s
          Nov 28 '18 at 9:17













          Okay otherwise i would highly recommend to use XMLHttpRequest

          – Jonathan
          Nov 28 '18 at 9:19





          Okay otherwise i would highly recommend to use XMLHttpRequest

          – Jonathan
          Nov 28 '18 at 9:19













          Is there any reason to especially use the native http plugin? Because it would work way more better with a XMLHttpRequest

          – Jonathan
          Nov 28 '18 at 9:25





          Is there any reason to especially use the native http plugin? Because it would work way more better with a XMLHttpRequest

          – Jonathan
          Nov 28 '18 at 9:25













          Yes. Because of cors error, i'm using native http

          – Asmitha j.s
          Nov 28 '18 at 9:42





          Yes. Because of cors error, i'm using native http

          – Asmitha j.s
          Nov 28 '18 at 9:42













          You will always get a cors error when you dont set Request headers. Doesnt matter what you are using to do the post request

          – Jonathan
          Nov 28 '18 at 9:46





          You will always get a cors error when you dont set Request headers. Doesnt matter what you are using to do the post request

          – Jonathan
          Nov 28 '18 at 9:46


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53511831%2fionic-native-http-post-is-not-sending-data-to-the-server%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks