nativescript-community / https

Secure HTTP client with SSL pinning for Nativescript - iOS/Android
https://nativescript-community.github.io/https/
Other
50 stars 42 forks source link

Malformed Data from PHP ! #56

Closed kefahB closed 4 years ago

kefahB commented 4 years ago

Hi @EddyVerbruggen ,

I try to implement your plugin but I receive a malformed data from php ! with fetch module it work as expected

To debug I send a response like this from php :

      $headers = [
            'Content-type' => 'application/json; charset=utf-8',
            'Accept' => 'application/json',
        ];
        $l = ["id", "l", "lol"];
        error_log(json_encode($l));
        $data =  \GuzzleHttp\json_encode($l);
        return new Response(200, $headers, $data);

look it is malformed

CONSOLE LOG file:///app/views/menuManager/menuManagerVM.ts:57:24: (
id,
l,
lol
)
kefahB commented 4 years ago

It is for some reason the data come one success the data.enumerateKeysAndObjectsUsingBlock and data.class().name both are undefined ! because of this the condition it go to the else where return the data as it from the server !

also the content is empty but

Tried to replace this line

} else {
      content = data;
}

By this and it work perfectly ! on my server I do nothing special !

} else {
      let serial = NSJSONSerialization.dataWithJSONObjectOptionsError(data, NSJSONWritingOptions.PrettyPrinted);
      content = NSString.alloc().initWithDataEncoding(serial, NSUTF8StringEncoding).toString();
}