我正在尝试通过http监控apache服务器。我正在使用的代码如下所示。
byte[] buffer = new byte[8192];
byte[] outputBuffer = new byte[8192];
int bytesRead = 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
BufferedInputStream bis = new BufferedInputStream(sourceUrl.openStream());
while (true) {
bytesRead = bis.read(buffer);
if (bytesRead == -1)
break;
baos.write(buffer, 0, bytesRead);
}
bis.close();
outputBuffer = baos.toByteArray();
baos.close();
return outputBuffer;
}catch{}
我期望这些值作为名称-值对。但有时我得到如下所示
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=LoginAction.action">
</head>
<body>
<p>Loading ...</p>
</body>
</html>
为什么会这样。我应该在代码中做什么来获得正确的值?请帮忙