当我尝试从JBoss服务器查询一些JSON时,我正在从服务器运行java.net.SocketException: Unexpected end of file
。我希望有人能发现我出错的地方。或者有没有人有任何建议从我的Jboss服务器中提取这个JSON?
try{
URL u = new URL("http://localhost:9990/management/subsystem/datasources/data-source/MySQLDS/statistics?read-resource&include-runtime=true&recursive=true");
HttpURLConnection c = (HttpURLConnection) u.openConnection();
String encoded = Base64.encode(("username"+":"+"password").getBytes());
c.setRequestMethod("POST");
c.setRequestProperty("Authorization", "Basic "+encoded);
c.setRequestProperty("Content-Type","application/json");
c.setUseCaches(false);
c.setAllowUserInteraction(false);
c.setConnectTimeout(5000);
c.setReadTimeout(5000);
c.connect();
int status = c.getResponseCode(); // throws the exception here
switch (status) {
case 200:
case 201:
BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line+"\n");
}
br.close();
System.out.println(sb.toString());
break;
default:
System.out.println(status);
break;
}
} catch (Exception e)
{
e.printStackTrace();
}