我有一个与IIS6.0服务器有httpurlConnection的小程序。
服务器响应分块数据,但有时(某些浏览器)我有问题。
服务器应答卡在一定的缓冲区中,当服务器超时关闭连接时到达我。
url = new URL(urlStr);
huc = (HttpURLConnection) url.openConnection();
huc.setDefaultUseCaches(false);
huc.setAllowUserInteraction(true);
huc.setDoInput(true);
huc.setUseCaches(false);
huc.setRequestProperty("Pragma", "no-cache");
huc.setRequestProperty("Cache-Control", "no-cache");
huc.setRequestProperty("Expires", "-1");
huc.setRequestProperty("Content-type", "text/html");
InputStream is = huc.getInputStream();
...
while (!trunkStop) {
while (errorConnection && !trunkStop) {
connectToServer();
if (errorConnection) {
sleepThread();
}
}
while (!errorConnection && !trunkStop) {
readData();
}
...
}
...
void readData() {
if (trunkStop) {
return;
}
try {
readLine();
addTask();//put to task queue
} catch (Exception e) {
getLogger().log(Level.WARNING, "Error connection...");
}
}
...
String readLine() throws IOException, InterruptedException {
sb = new StringBuilder();
int prev = -1;
while (!errorConnection && !trunkStop) {
read = is.read();
if (read == -1) {
if (System.currentTimeMillis() - timer > 150000) {
getLogger().log(Level.SEVERE, "RECONNECT BY TIMEOUT");
errorConnection = true;
}
Thread.sleep(10);
continue;
} else if (read == 13) {
} else if (read == 10 && prev == 13) {
break;
} else {
sb.append((char) read);
System.out.print((char) read);
}
prev = read;
timer = System.currentTimeMillis();
}
return sb.toString();
}
某些浏览器缓冲区,我不知道。
此时,IIS已经发送了答案,这是客户端问题,
IE7,Java1.60EY16
有什么想法吗?