0

I'm developing an android-app for my website. On the website you can create users and login with them.

Now i want this on the App to. The login function is the problem.

I've got all the forms (Username & Password). Now I want to connect to an custom adress on my webserver ex: http://domain.com/login.php?username=MyUserName&password=MyPassWord

This page will return "1" if the login was correct, and "0" if not. And I want my app to connect to this adress and then get the content/result my webserver leaves.

Please help my, I've been sitting HOURS tryin to get it right.

1 Answers1

1

I believe what you're looking for is the BasicHttpContext and the DefaultHttpClient:

HttpContext httpContext = new BasicHttpContext();
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://domain.com/login.php?username=MyUserName&password=MyPassWord");
HttpResponse response = httpClient.execute(httpGet, httpContext);

Haven't tested the code, but I think it should to the trick.

Also remember that you app must have the appropriate INTERNET permission in your manifest file to allow Internet access.

Julian
  • 20,008
  • 17
  • 77
  • 108
  • Thanks! It seems to work pretty good. But I did some change in the code. Surround HttpResponse response = httpClient.execute(httpGet, httpContext); with try;catch – Philip Andersson Nov 27 '10 at 13:52
  • But when i try it out, I get response to : "org.apache.http.message.BasicHttpResponse@44943060 – Philip Andersson Nov 27 '10 at 13:53
  • Yes of course, the response you get is of the type `HttpResponse` (http://developer.android.com/reference/org/apache/http/HttpResponse.html). You then have to parse this result to get the data you're interested in (look in the documentation at the methods inherited from `HttpMessage`). – Julian Nov 27 '10 at 13:57
  • By the way, you might find some help on how to deal with the response using a `ResponseHandler` as described in the answer to this question: http://stackoverflow.com/questions/2573064/how-to-print-out-returned-message-from-httpresponse – Julian Nov 27 '10 at 14:25
  • Yeah, thanks! This took only 30mins, and before those, it took me 3h without result. Thanks! – Philip Andersson Nov 27 '10 at 14:30