Reputation: 49
I have an Android project created by Cordova witch consume a REST service provided from spring Rest projet on localhost using AngularJs, I try to access to the resource using following code:
'use strict';
angular.module('myService', ['ngResource']).
factory('Demande', function ($http, $resource) {
$http.defaults.useXDomain = true;
return $resource('http:// localhost:8080\:8080/springrestprojet/rest/myobject/:id', {}, {
'save': {method:'PUT',
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS, PUT',
'Access-Control-Allow-Headers': 'Origin, Content-Type, Accept',
'Access-Control-Request-Headers': 'X-Requested-With, accept, content-type',
'Accept':'application/x-www-form-urlencoded, multipart/form-data',
'Access-Control-Allow-Credentials': 'true'}},
});
});
I can open to file
C:\Users\User\Mobile\AppClient\platforms\android\assets\www\index.html
and that shows me the correct result.
but when I run application in the emulator that gives me just empty views (no data rest). I changed the ip adress of resource to 10.0.2.2 and to the ip adresse of my machine but that still not working!
I guess there is no communication between my emulator genymotion device and the localhost!
Any proposition please?
Thanks.
Upvotes: 0
Views: 296
Reputation: 2819
Genymotion is running in VirtualBox. You have to change the network configuration. As stated on http://bbowden.tumblr.com/post/58650831283/accessing-a-localhost-server-from-the-genymotion:
The name of the network is vboxnet0, and if you run “ifconfig vboxnet0” (or “ipconfig vboxnet0” if running Windows) on your host machine, you should receive the IP address of your host on the vboxnet0 network. The default IP is most likely 192.168.56.1. This is the IP address to use when accessing your host machine from the Genymotion emulator.
Upvotes: 1