ionic native HTTP call with content-type text/plan?

nit*_*ish 2 javascript http ionic-framework ionic3 angular

I am trying to make a HTTP call and my Content-Type is text/plan but I am working with ionic-native/http which only take object and array,here is what I have tried

Error: advanced-http: "data" argument supports only following data types: Array, Object

TestIR(item){

  let headers = { 'Content-Type': 'text/plain'}; 
  let sender ='sendir,1:1,0,';
  let code = item.keys[10].code;
  let body = sender+code;
  let url= "http://10.75.0.120/v2/CI00e0148a";

  this.httpNative.setDataSerializer( "json" );
  this.httpNative.post(url,body,headers).then(val=> 
   {console.log(val)}).
  catch(e=>{console.log(e)})

}
Run Code Online (Sandbox Code Playgroud)

Gle*_*ies 7

假设:正在使用的 HTTP 插件是cordova-plugin-advanced-http,从 Ionic Docs 链接。

将数据序列化器设置为 json 告诉插件期望一个 javascript 对象,但您发送的正文是一个字符串

解决方案1

如果您要向其发送数据的 API 可以处理它,请将数据序列化程序设置为"utf8".

this.httpNative.setDataSerializer( "utf8" );
Run Code Online (Sandbox Code Playgroud)

这告诉插件期待文本。

解决方案2

在调用 POST 之前将主体更改为对象。

body = JSON.parse(json);
Run Code Online (Sandbox Code Playgroud)

您传递给的字符串JSON.parse()必须是有效的 json。

编辑:删除了对现已修复的错误的引用