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)
假设:正在使用的 HTTP 插件是cordova-plugin-advanced-http,从 Ionic Docs 链接。
如果您要向其发送数据的 API 可以处理它,请将数据序列化程序设置为"utf8".
this.httpNative.setDataSerializer( "utf8" );
Run Code Online (Sandbox Code Playgroud)
这告诉插件期待文本。
在调用 POST 之前将主体更改为对象。
body = JSON.parse(json);
Run Code Online (Sandbox Code Playgroud)
您传递给的字符串JSON.parse()必须是有效的 json。
编辑:删除了对现已修复的错误的引用
| 归档时间: |
|
| 查看次数: |
5391 次 |
| 最近记录: |