D
D
dantedelvengo2019-02-19 12:56:54
JavaScript
dantedelvengo, 2019-02-19 12:56:54

404 error when connecting to the site's api, what permissions are needed for the apk application?

Good time! I set up api for my application, which I create on vue js and then mount via cordova to apk and ipa. I created a php file handler for the test on a remote site that accepts requests (for now, simple ones purely for the test) and issues a response. the following content of acore.php:

header('Access-Control-Allow-Origin: *'); 
header("Content-type: application/json; charset: utf-8");;
$v['id'] ='11'; $v['nn']='22';
echo json_encode($v);


and this is how I send a request there in the application:

var request = new XMLHttpRequest();
                request.open('GET', 'http://www.****.com/hyst/acore.php', false);

                request.onload = function() { 
                  if (request.status >= 200 && request.status < 400) {
                  var data = JSON.parse(request.responseText);
                  alert(data.id);
                  } else {
                  alert(request.status+' error');
                  }
                };
                request.send();


The problem is that when I test the application in disassembled form in the browser, everything works, the request goes away and the response returns to me, but after I collect all this cordova in apk and install it on my phone and try it there, I get a 404 error with an alvert that I prescribed above.

I also tested on pointing this service https://jsonplaceholder.typicode.com/todos/1
the same story, which suggests that the matter is in Cordova itself, that during assembly it is necessary to set some permissions for html requests from the application itself to third-party sites
tell me who knows how to solve this?
here is what I have in config.xml at the root of the application

5c6bd2c6a0ae1992407297.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dantedelvengo, 2019-02-20
@dantedelvengo

Got it! The fact is that after the 4th version of Cordova, the application limits the application in global requests to other sites, in short, you need to go to the root folder of your project where config.xml is located and write it on the command line
and after the plugin is installed, change the access lines in the config.xml file from

<allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />

on
and everything will magically start working))
the information is taken from the thanks @Total Pusher

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question