silkimen / cordova-plugin-advanced-http

Cordova / Phonegap plugin for communicating with HTTP servers. Allows for SSL pinning!
MIT License
400 stars 321 forks source link

[Bug] [Android] advanced-http: an error occured during post processing response: Cannot read properties of undefined (reading '0') #463

Closed Seeroy closed 1 year ago

Seeroy commented 2 years ago

Describe the bug Trying to get json with GET request from VK API. Error: "advanced-http: an error occured during post processing response: Cannot read properties of undefined (reading '0')"

System info

Minimum viable code to reproduce If applicable, add formatted sample coding to help explain your problem.

const options = {
      method: 'get'
    };
    cordova.plugin.http.sendRequest(url, options, function (response) {
      callback(response);
    }, function (response) {
      console.log("HTTP ERROR");
      console.log(response);
    });
silkimen commented 2 years ago

Is the URL publicly available? Would you please share the URL?

Seeroy commented 2 years ago

I cant send URL, because without access_token parameter URL is not accessible. I can send the response of the URL.

Seeroy commented 2 years ago

response.zip Here is a sample response from an VK API. Sensetive data removed

silkimen commented 2 years ago

Thanks for providing this data, but I'll need to debug the code which is not possible with the JSON repsonse only. Did you try to debug it on your side and find out in which line exactly it is throwing?

silkimen commented 2 years ago

Oh and you should also try to replace the content of the success callback:

cordova.plugin.http.sendRequest(url, options, function (response) {
  // comment this line
  // callback(response);

  // and just log the response to the console
  console.log(response);
}, function (response) {
  console.log("HTTP ERROR");
  console.log(response);
});

Is it still throwing?

Seeroy commented 2 years ago

Its throwing only, if im trying to decode JSON using JSON.parse() This code throwing error too

cordova.plugin.http.sendRequest(url, options, function (response) {
      console.log(JSON.parse(response));
    }, function (response) {
      console.log("HTTP ERROR");
      console.log(response);
    });
silkimen commented 2 years ago

Okay then, I guess your problem is not related to this plugin in this case. You are receiving invalid JSON data from your endpoint which can't be parsed.

silkimen commented 1 year ago

Closing this, feel free to open a new issue, if this won't solve your problem! 👍