我有一個Applet與HttpUrlConnection到IIS 6.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,java 1.6.0_16
任何想法?
任何代碼向我們展示? 你是什麼意思與某些緩衝區(哪裏是緩衝區IIS或小應用程序)? 哪些版本的IIS,瀏覽器,Java? – jitter 2009-10-19 14:40:24