以下链接返回Customers实体集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")
在此之后编码以将条目计数为整数?
答案 0 :(得分:2)
您需要从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
的输出流后,您必须执行此操作。这显然意味着您将请求数据写入连接的输出流并从连接的输入流中读取响应数据