javaandroidandroid-emulatornanohttpd

Android Emulator - How to send a http post request to it?


I created an app that uses nanohttpd to set up a small http listener. To test this i need to be able to send post request to the webserver on the emulator from my host machine using postman.

So that i would be able to send a post request to http://:1234/, which the app will then interpret. The app is working fine on my tablet, but for testing porpuses i need to find a way to do this on emulators as that would make my testing more flexible

How can this be achieved ?


Solution

  • You can set a redirect port from your host machine to your app's listening port. For instance if your app is listening on port 8080, then you can use set the redir as follows:

    telnet localhost 5554
    

    Then once you are authorized, enter

    redir add tcp:8080:8080
    

    Now any request sent on your local machine's localhost:8080 will be sent your emulator's localhost:8080. Now you can use Postman to send a request on localhost:8080 on your local machine.