I developed a simple HTTP server myself, but it gets stuck every time the form is submitted. . Can anyone help me figure out where the problem is?
This is the content of my form, which is a very simple three input boxes
if(bufferedReader.ready()) {
StringBuilder stringBuilder = new StringBuilder() ;
int ch ;
while((ch = bufferedReader.read()) != -1){
stringBuilder.append((char)ch) ;
System.out.println(stringBuilder) ;
}
line = stringBuilder.toString() ;
}
I encapsulated the input stream of the socket in this bufferReader, and then it got stuck every time while((ch = bufferedReader.read()) != -1){
This line
#The output of the console shows that all the form content has been obtained, but why not return -1? Is it because the browser uses HTTP1.1 and is waiting for the return result to enter the next request? Or is there something wrong with my program? I use blocking IO
The problem has been solved, it is the problem of long links. . .
I guess you didn’t close the socket!