【发布时间】:2018-04-01 00:37:22
【问题描述】:
我正在尝试使用带有 IONIC 3 的 HTTP 本机发送 JSON 数组作为参数。这是请求:
HTTPResponse = await this.http.post(url,
body, headers);
这是完整的代码。我正在使用来自“@ionic-native/http”的 HTTP。这是完整的代码
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);
我在其他请求中使用了类似的代码,一切正常,唯一的区别是请求在 JSON 正文中有一个简单的参数。这是正常的请求:
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);
【问题讨论】: