-8

我在网上搜索过,但无济于事,我没有找到问题的答案。

我需要我的 android 应用程序连接到我的网络服务器。

例子https://SERVER-ADDRESS:PORT/

我怎样才能做到这一点?

4

1 回答 1

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();
    }
于 2012-11-28T11:38:04.790 回答