UTF-8 error Iphone emulator

Hello,

I am having a problem with my application. I am sending data in JSON to an external server for it to process the data sent by the user in my application.

When I use the ionic browser I have no problem, the data is arriving correctly.

But when I send from my emulator under iOs, the data is sent only when there is no uft8 character.

My code :

submitForm() {

    if (this.myGroup.valid) {
      this.http.setDataSerializer('json');
      // Création du système d'envoi via POST à mon controller PHP
      this.http.post("http://127.0.0.1:80/roadAppSys/signal.php?name=" + this.myGroup.value.name + "&email=" + this.myGroup.value.email + "&objet=" + this.myGroup.value.objet + "&signalement=" +this.myGroup.value.signalement + "&idcourse=" + this.idCourseDataSignalement, this.myGroup, {})
          .then(res => {
        }, error => {
          this.presentAlert2();
       });

      this.modalController.dismiss();
      this.presentToast();
    }else{
      this.presentAlert();
    }

    //console.log(this.myGroup.value);
  }

}

Thank’s for help !

I use Angular’s HTTP client for all API calls.

I don’t know enough about the plugin you are using but do not believe that it is taking your query string and converting the key/value pairs to JSON.

With Angular’s client, you can easily pass a JSON object and strongly type all methods.

1 Like

I edited my code to adapt it

this.http.post("http://127.0.0.1:80/roadAppSys/signal.php?name=" + this.myGroup.value.name + "&email=" + this.myGroup.value.email + "&objet=" + this.myGroup.value.objet + "&signalement=" +this.myGroup.value.signalement + "&idcourse=" + this.idCourseDataSignalement, this.myGroup, {})
    .subscribe((data2) => {
      }, error => {
        this.presentAlert2();
     });

And now, I have this error :

TypeError: JSON.stringify cannot serialize cyclic structures.

Problem resolve :

this.http.post("http://127.0.0.1:80/roadAppSys/signal.php?name=" + this.myGroup.value.name + "&email=" + this.myGroup.value.email + "&objet=" + this.myGroup.value.objet + "&signalement=" +this.myGroup.value.signalement + "&idcourse=" + this.idCourseDataSignalement, '', {})
    .subscribe((data2) => {
      }, error => {
        this.presentAlert2();
     });

I would like to urge anybody coming across this thread to consider @danieldugger’s comment instead of the post above this one that is currently considered the “solution”.

Manually building query strings is error-prone and difficult to read and maintain. Using Angular’s HttpClient allows your app code to be cleaner, emphasizing the important and distinct parts of it that make it truly your app.