2010-11-27 105 views
0

我正在爲我的網站開發android-app。在網站上,您可以創建用戶並使用它們登錄。從網址獲取內容/ streak

現在我想要這個應用程序。登錄功能是問題。

我已經得到了所有的表格(用戶名爲&)。 現在我想連接到我的網絡服務器ex上的自定義地址:http://domain.com/login.php?username=MyUserName&password=MyPassWord

如果登錄正確,此頁面將返回「1」,否則返回「0」。 我希望我的應用程序能連接到這個地址,然後獲取我的web服務器離開的內容/結果。

請幫助我,我一直坐在小時試着讓它正確。

回答

1

我相信你要找的是什麼BasicHttpContextDefaultHttpClient

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); 

沒有測試的代碼,但我認爲它應該到的伎倆。

還請記住,您的應用必須在清單文件中具有相應的INTERNET權限才能訪問Internet。

+0

謝謝!它似乎工作得很好。但是我在代碼中做了一些改變。 Surround HttpResponse response = httpClient.execute(httpGet,httpContext); with try; catch – 2010-11-27 13:52:00