2012-11-28 48 views

回答

0
try{ 
String url = "https://SERVER-ADDRESS:PORT/site/login?username=" + user + "&password=" + password; 
HttpParams params = new BasicHttpParams(); 
     HttpConnectionParams.setConnectionTimeout(params, 1000 * 60 * 2); 
     HttpConnectionParams.setSoTimeout(params, 0); 
     HttpClient httpClient = new DefaultHttpClient(params); 

     //prepare the HTTP GET call 
     HttpGet httpget = new HttpGet(url); 
     //get the response entity 
     HttpEntity entity = httpClient.execute(httpget).getEntity(); 

     if (entity != null) { 
      //get the response content as a string 
      String response = EntityUtils.toString(entity); 
      //consume the entity 
      entity.consumeContent(); 

      // When HttpClient instance is no longer needed, shut down the connection manager to ensure immediate deallocation of all system resources 
      httpClient.getConnectionManager().shutdown(); 
      } 
    }catch (Exception e) { 
     e.printStackTrace(); 
    } 
+0

嘿,這太棒了!我怎樣才能讓用戶不得不輸入他們自己的用戶名和密碼。併發送以下http請求https:// SERVER-ADDRESS:PORT/site/login? 用戶名= USER&密碼= PASS –

+0

字符串URL = 「https://開頭SERVER-ADDRESS:PORT /站點/登錄用戶名=」 +用戶+ 「&密碼=」 +密碼; – Nermeen

+0

非常感謝,這非常有幫助! –