假设有个HTTP请求,浏览器获得如下HTTP响应:
HTTP/1.1 200 OK
Date: Tue, 12 Jul 2016 21:36:12 GMT
Content-Length: 431
Content-Type: text/html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Your Title</title>
</head>
<body>
<form id="login" name="login" method ="Post" action="Post.html">
Username:<input id="id1" name="txtUserName" type="text" /><br/>
Password:<input id="id2" name="txtPWD" type="text" /><br/>
<input id="id3" name ="subLogin" type="submit" value="submit123" />
</form>
</body>
</html>
表单标签<form>用于收集用户的输入。其中method属性用于提交时,采取的HTTP方法。而action属性用于提交HTTP时的URL。当点击submit按钮时,向原http服务器发送了一个新的HTTP请求:
POST /Post.html HTTP/1.1
Host: 192.168.1.109:8080
Content-Length: 45
txtUserName=111&txtPWD=222&subLogin=submit123
POST方法是因为 method ="Post"这个属性;/Post.html资源是因为action="Post.html"这个属性。
HTTP服务程序应重新准备好Post.html的文本内容,发送会浏览器。
如此一来,HTTP服务程序与用户浏览器就可以进行“交互”了。