Cordova (IONIC) http post does not work even after including header details

I am using Ionic 4 to create a small mobile app. The back-end is C# WebAPI. I need to submit some data to the server. And it does not work.

The Code:

NewsDetails = {
    "ServerID": "1",
    "Title": "Test",
    "Source": "Self",
    "Body": "Hello world"
  const httpOptions = {
      headers: new HttpHeaders({
        'Content-Type':  'application/json'
      };"", this.NewsDetails, httpOptions)
      .subscribe(data => {
      }, (err) => {
        console.error("unable to connect to server:", JSON.stringify(err));

The above code produces the following error:

 "statusText":"Unknown Error",
 "message":"Http failure response for 0 Unknown Error",

I tried updating the same from POSTMAN application and works fine. Any idea the reason for the error?

Thanking u in advance.

1 answer

  • answered 2020-04-03 07:31 Tomislav Stankovic

    Android 8: Cleartext HTTP traffic not permitted

    Inside config.xml you can add:

    <application android:usesCleartextTraffic="true" />

    like this:

    <platform name="android">
       <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="">
             <application android:usesCleartextTraffic="true" />