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);