【问题标题】: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 的输出流之后执行此操作。这显然意味着您将请求数据写入连接的输出流并从连接的输入流中读取响应数据