java.net.SocketException: Unexpected end of file
当我尝试从我的 JBoss 服务器查询一些 JSON 时,我遇到了来自服务器的问题。我希望有人能发现我哪里出错了。或者有人对从我的 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();
}