I want to connect my moodle website to开发者_如何学C android such that the user login is done on android device via buttons made by GUI. And my moodle website should act as an server on my system. How to do this web server configuration?
Or you can request the data from the server the same way you do from the browser / desktop app, using HttpGet and HttpPost.
For authentication you should use HttpPost
with UrlEncodedFormEntity
:
[...]
DefaultHttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost(LOGIN_SERVLET_URI);
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("userName", userName));
params.add(new BasicNameValuePair("password", password));
UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(params, HTTP.UTF_8);
httppost.setEntity(p_entity);
HttpResponse response = client.execute(httppost);
HttpEntity responseEntity = response.getEntity();
[...]
Then you can parse your response in the appropriate manner (if it's xml than with SAXParser
and XMLReader
, etc).
You'll have to create things like WebServices
on your website's end, which will let your Android apps interact with the data of your website.
精彩评论