我想將我的moodle網站連接到android,以便用戶登錄在android設備上通過GUI所做的按鈕完成。我的moodle網站應該充當我係統上的服務器。如何做這個Web服務器配置?Android網絡服務器連接?
1
A
回答
0
您必須在您的網站上創建類似WebServices
的東西,這會讓您的Android應用與您網站的數據互動。
1
或者您可以使用HttpGet和HttpPost以與瀏覽器/桌面應用程序相同的方式從服務器請求數據。
對於身份驗證,你應該使用HttpPost
與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();
[...]
然後你就可以解析以適當的方式你的迴應(如果它的XML比SAXParser
和XMLReader
等)。
這很好。謝謝! – 2011-04-25 11:15:24