Socket client = ss.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter out = new PrintWriter(client.getOutputStream());
out.print("HTTP/1.1 200 \r\n");
out.print("Content-Type: text/HTML\r\n");
out.print("\r\n");
out.print("<form method='POST' action=''>First name: <input type='text' name='FirstName' value='Mickey'><br><input type='submit' value='Submit'></form>"
+ "\r\n");
String line;
while ((line = in.readLine()) != null){
if(line.length() == 0) {
break;
}
System.out.println(line);
}
System.out.println("lõpp");
out.close();
in.close();
client.close();
这个代码在按下提交后给我这个。
POST / HTTP/1.1
Host: localhost
Connection: keep-alive
Content-Length: 16
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: http://localhost
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36
Content-Type: application/x-www-form-urlencoded
DNT: 1
Referer: http://localhost/
Accept-Encoding: gzip, deflate
Accept-Language: et,en-US;q=0.8,en;q=0.6
Cookie: s_ncomui_ev14=%5B%5B%27link%27%2C%271423849771968%27%5D%5D
应该有一个balnk line和我的POST变量。 in.readLine()只是阻止代码。 Browswer只是不断加载。我必须手动制止它。