HTTP GET using localhost

6

I'm creating an application using phonegap + onsen framework that will be powered by Web Services (RestFul).

But I can not make a conversation between the two parties.

My call to the Web Service looks like this:

$http.get('http://localhost:8080/WhereToJamServer/ws/colacao/getDataAtual', {})
    .success(function(data) {
        alert(data);
    })
    .error(function() {
        alert('error');
    });

And my Web Service looks like this:

@Path("/colacao")

@GET
@Path("getDataAtual")
@Produces(MediaType.TEXT_HTML)
public String getDataAtual() {
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
    return sdf.format(new Date());
}
If I change localhost to 10.0.2.2 or the local IP (IPv4) of my machine does not work either.

NOTE: When I call the URL through the browser it works normally.

Any suggestions?

    
asked by anonymous 30.07.2015 / 03:34

2 answers

1

SOLUTION

I was able to connect to my localhost only by changing my localhost URL to the IPv4 address of my Wifi .

To get this address is to open the Command Prompt windows and type ipconfig . The IPv4 that you should look for is from your Wifi ( Ethernet Ethernet Adapter ).

 http://DIGITEAQUI:8080/WhereToJamServer/ws/colacao/getDataAtual

Before I could not because I put the IPv4 of my Ethernet Adapter Local Connection (better known as cable). I did not even care.

And best of all, you do not even need the cable to access the Web Service =)

    
14.10.2015 / 14:12
0

It may be a crossdomain problem, check the whitelist of your phonegap application, take a look at the official documentation =

link

If you still continue the error, here is the return of the $ http.get request, which error is included.

    
30.07.2015 / 13:48