by Stefano Fiscale.
For those who have had the same problem, here's the solution:
from terminal execute the following command:
$ curl -c - -i -F'username=myusername' -F'password=mypassword' -F'service=moodle_mobile_app' -X POST http://mymoodlesite/login/token.php
from terminal execute the following command:
$ curl -c - -i -F'username=myusername' -F'password=mypassword' -F'service=moodle_mobile_app' -X POST http://mymoodlesite/login/token.php
The response will be something like:
{"token":"696ded7cd77a8041c0332423a9e8c78b","privatetoken":null}#