I’m trying to send a JSON array as parameter using HTTP native with IONIC 3. This is the request:
HTTPResponse = await this.http.post(url,
body, headers);
This is the complete code. I’m using HTTP from from ‘@ionic-native/http’. This is the complete code
import { HTTP, HTTPResponse } from ‘@ionic-native/http’;
[…]
let body = ‘[{“userId”: 1, “timestamp”:“2018-10-12T18:00:00.000+02”,
“audit”:“MENUTEST”},{“userId”: 1, “timestamp”:“2018-10-
12T18:00:00.000+02”, “audit”:“MENUTEST”},{“userId”: 1,
“timestamp”:“2018-10-12T18:00:00.000+02”, “audit”:“MENUTEST”}]’;
//Auth header
let headers = { Authorization: Bearer ${token}
};
let httpResponse: HTTPResponse = await
this.http.post(URL_data, JSON.parse(body), headers);
I’m using similar code with other request and all is going fine, the only difference is that the request that is going have a simple parameters in JSON body. This is the request that is going fine:
import { HTTP, HTTPResponse } from ‘@ionic-native/http’;
[…]
let body = ‘{ “username”: “usuario.prueba1”, “password”: "’ +
Md5.hashStr(‘prueba’) + ‘", “customerCode”: “1234DEV” }’;
let httpResponse: HTTPResponse = await
this.http.post(URL_login, JSON.parse(body), headers);