How to use login to CI webService from Android - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to use login to CI webService from Android (/showthread.php?tid=52074) |
How to use login to CI webService from Android - El Forum - 05-29-2012 [eluser]miroslavign[/eluser] Hi, I am using the latest download of CI (2.1.0) and have build and used the web service (REST) from Android application using Android Asynchronous Http Client from http://loopj.com/android-async-http/ Nothing fancy, just a http helper for android. Anyways, the stuff works, until I change the login in rest.php from none ('') to basic or digest. First of all, i do not understand the difference between basic and digest, and secondly, how to send user and password to CI ? So, on Android client I've tried: AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.put("username", "admin"); params.put("password", "1234"); client.get("http://10.0.2.2/Menjacnica/index.php/api/menjacnice_api/menjacnice", params, new AsyncHttpResponseHandler()... and it does not work. Again, if on the CI side I return to no login (''), the Android client is getting the correct response from my CI controller. Any ideas? How to use login to CI webService from Android - El Forum - 05-29-2012 [eluser]gRoberts[/eluser] Is your REST api expecting GET or POST to perform the login? Looking at your URL, it's post, but looking at your AsyncHttpClient code, your performing a GET. How to use login to CI webService from Android - El Forum - 05-29-2012 [eluser]miroslavign[/eluser] It is working with get: ... function menjacnice_get() { ... And it is working as expected when the REST login is none How to use login to CI webService from Android - El Forum - 05-29-2012 [eluser]gRoberts[/eluser] I'm not 100% sure on how the REST api works, however, it's likely that yours is configured to accept login's that are in "plaintext", which I assume Login type '' uses. Digest (http://en.wikipedia.org/wiki/Digest_access_authentication) and Basic (http://en.wikipedia.org/wiki/Basic_access_authentication) both encrypt/hash the username/password when passing it to the server to login, so it's likely that it's failing because your Android app is not encryping/hashing the username/password correctly. How to use login to CI webService from Android - El Forum - 05-29-2012 [eluser]miroslavign[/eluser] I don't if that might be the problem, but it is worth trying to investigate. How to use login to CI webService from Android - El Forum - 05-29-2012 [eluser]miroslavign[/eluser] It seem you were right, in Android Asynchronous Http Client, there is a patch that adds a method: public void setBasicAuthCredentials(String user, String pass) that adds a Base64 encoding ! Will try to patch and build a newer lib right now. Thank you gRoberts How to use login to CI webService from Android - El Forum - 05-29-2012 [eluser]miroslavign[/eluser] Yes, it works now! Should mark this as resolved. |