【问题标题】:Getting the count of entries in entitySet in OData using java使用java获取OData中entitySet中的条目数
【发布时间】:2014-05-23 06:37:20
【问题描述】:

以下链接返回客户实体集http://services.odata.org/Northwind/Northwind.svc/Customers/$count 中的条目数

如何使用 java 得到这个数字?

 URL url = new URL("http://services.odata.org/Northwind/Northwind.svc/Customers/$count");
 HttpURLConnection conn = (HttpURLConnection) url.openConnection();
 conn.setRequestMethod("GET")

在此之后要编写什么代码以将条目计数为整数?

【问题讨论】:

    标签: java rest odata httpconnection olingo


    【解决方案1】:

    你需要从HttpURLConnection输入流中读取数据,比如

     BufferedReader in = new BufferedReader(new InputStreamReader(
                                        conn.getInputStream()));
            String count;
            while ((count = in.readLine()) != null) 
                //this will print the count in count variable
                System.out.println(count);
            in.close();
        }
    

    注意:您必须在将请求写入HttpURLConnection 的输出流之后执行此操作。这显然意味着您将请求数据写入连接的输出流并从连接的输入流中读取响应数据

    【讨论】:

    • 这里为什么不能使用getContent()方法?
    猜你喜欢
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多