@ionic-native/http - post error Content-Type body Json


#1

What am I doing wrong with the post to convert the body to json?

Import my file .ts

import { HTTP } from '@ionic-native/http';

Creation arguments for http post

var url = "https://gateway.watsonplatform.net/conversation/api/v1/workspaces/12d9fbb9-0914-441f-9c1b-8076630f0522/message?version=2017-05-26";

var body = { "alternate_intents": false, "input": { "text": "cerveja" } };
this.http.useBasicAuth("juca", "1234567");
this.http.setHeader('Accept', 'application/json');
this.http.setHeader('Content-Type', 'application/json');
this.http.post(url, body, {})
      .then(data => {
        console.log(data.data); // data received by server
      })
      .catch(error => {
        console.log(error.error); // error message as string
      });

I tried to use the new FormData(), but server does not understand value for body

 let bodys = new FormData();
 var input = "{'text': 'cerveja'}";
 bodys.append('alternate_intents', 'false');  
 bodys.append('input', input);


#2

Why aren’t you using the ordinary Angular Http?


#4

Hi @moisesvni, did you solve this issue ? I’m facing the same kind of problem while posting FormData type object using ionic native HTTP

Thanks