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

(8000 is my port , you can put yours)

so that Any device or host (ip) could access

if you put 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


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:


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("");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

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

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