score:2

Accepted answer

FINALLY! i have found the solution to my problem

when running the built-in php server . We need to specify this command

php bin/console server:run 0.0.0.0:8000

(8000 is my port , you can put yours)

so that Any device or host (ip) could access

if you put 127.0.0.1 only your localhost will be allowed

That's why i couldn't get the Api even i was connected to my localhost via wifi hotspot

It's ok now

score:1

Are you able to install this cURL App for Android?

Then use on your Android (is this a real phone or an emulator) open a cURL window and then enter:

cURL http://192.168.43.13:8000/

I tried this same kind of setup with a real Android phone and the above indicated cURL app and put in my Symfony web URL (on another PC), and the Android shows the correct html response back that I'm expecting.

At least this will help you verify functionality first.

Edit below this line:

Here is the code you might use since HttpClient was deprecated:

URL url = new URL("http://192.168.43.13:8000/api/horaire.json");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//conn.setRequestMethod("GET");

// read the response
System.out.println("Response Code: " + conn.getResponseCode());
InputStream in = new BufferedInputStream(conn.getInputStream());
String response = org.apache.commons.io.IOUtils.toString(in, "UTF-8");
System.out.println(response);

Not sure if you need to use the "setRequestMethod". But try out this change and see if that works for you.


Related Query

More Query from same tag