Ionic Advanced-http:标头值必须为字符串

时间:2019-05-20 09:19:59

标签: ionic-framework

离子在设备控制台上显示错误错误:advanced-http:无效的params对象,需要是带有字符串的对象 错误:advanced-http:无效的params对象,必须是带有字符串的对象。

  private http: HTTP
   verify(){

      this.http.get('http://outreach.pk/api/sendsms.php/sendsms/url?id=rchiginsurance&pass=igi123456&mask=IGInsurance&lang=English&type=xml',
         {
  params: {
  to: this.mobile.value,
  msg: this.number1
  }
  },
   {});

  }

2 个答案:

答案 0 :(得分:0)

您需要使用set来设置请求的标头,如下所示:

this.http.setHeader('*', String("Content-Type"), String("application/json"));
this.http.setHeader('*', String("Accept"), String("application/json"));

,您需要设置序列化器

this.http.setDataSerializer('json');

答案 1 :(得分:0)

由于标题为空,因此只需在标题对象中输入“ null”并设置序列化程序即可。例如:

this.http.setDataSerializer("json");
this.http.post(url, body, null).then(res => {....});

this.http.setDataSerializer("json");
this.http.post(url, body, {headers: {'Content-Type: application/json'}}).then(res => {....});

将其写在离子电容器2.4和ionic-native / http 5.29