叫休息网络服务?

beb*_*ebe 2 android

我是Android开发的新手.我想调用一个休息Web服务并显示一个简单的txt文件或xls文件.那可能吗?如果是的话,怎么样?先感谢您...

Mar*_*los 5

您可以为服务器发送POST并读取结果.

这是我使用JSON对象的实现,你应该做类似的事情:

        JSONObject obj = new JSONObject();
        obj.put("jsonrpc", "2.0");
        obj.put("method", "getSomething");

        JSONObject auth = new JSONObject();
        auth.put("email", "user");
        auth.put("password", "pass");

        params.put("auth", auth);
        obj.put("params", params);

        int TIMEOUT_MILLISEC = 10000; // = 10 seconds
        HttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
        HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
        HttpClient client = new DefaultHttpClient(httpParams);

        HttpPost request = new HttpPost("server address");
        try {
            StringEntity entity = new StringEntity(obj.toString());
            entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
                    "application/json"));
            request.setEntity(entity);

            ResponseHandler<String> handler = new BasicResponseHandler();
            String returnValue = client.execute(request, handler);
                    //returnValue has the return from the server.
        } catch (Throwable e) {
            e.printStackTrace();
        }
Run Code Online (Sandbox Code Playgroud)