HTTP GET using localhost

Asked

Viewed 535 times

6

I am creating an application using phonegap + Onsen framework that will be powered by Web Services (Restful).

But I can’t seem to get a conversation going between the two.

My call to the Web Service is like this:

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

And my web service is 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 for 10.0.2.2 or my machine’s local IP (Ipv4) does not work either.

NOTE: When I call the URL by the browser works normally.

Any suggestions?

  • Tests are being performed on an emulator or on a real device?

  • in a real apparatus

  • 1

    When you call the URL from the browser of your machine or of the real apparatus?

  • When I call the URL by the browser my PC works normally. By mobile I did not get to test. When I get home I will test this too.

  • I found the solution .... edited the post!

  • Just a hint, @vogeloco: the general procedure for when you find the solution yourself is to answer the question itself and accept the answer, so it is clear in the system that the question has been answered.

  • It’s done @fsanches, thanks!

Show 2 more comments

2 answers

1

SOLUTION

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

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

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

Before I had not succeeded because I put the Ipv4 of mine Ethernet adapter Local connection (better known as cable). I didn’t even care.

And best of all, you don’t even need the cable to access the Web Service =)

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.