In recent work, the client needs to send data to the server, using Http protocol, that is, Get and Post request operations. In general, Get is used to request data, and Post is used to upload data to the Update Server. Get requests should be safe and idempotent.
When a form is submitted, if the Method attribute of the form is set to get, the form is submitted in get mode to send data requests. The get Method is used, the information in the form is connected after the Url in the form of Key = Value & Key = Value. Use ASP. net mvc 3 For example:
View:
@ {ViewBag. title = "Http Get and Post learning analysis";}
Controller:
public class StudentController : Controller { public ActionResult Add(string userName, string passWord) { string information = "UserName: " + userName + "Password: " + passWord; return View(); } }
Initial run:
Enter 123456 In the UserName and Password text boxes, and click the Submit button:
The get request Headers:
Request URL:http://localhost:4126/?userName=123456&passWord=123456Request Method:GETStatus Code:200 OK
Request Headers:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3Accept-Encoding:gzip,deflate,sdchAccept-Language:zh-CN,zh;q=0.8Connection:keep-aliveHost:localhost:4126Referer:http://localhost:4126/User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19
Query String Parameters, connected to the Url
userName:123456passWord:123456
Response Headers:
Cache-Control:privateConnection:CloseContent-Length:408Content-Type:text/html; charset=utf-8Date:Sun, 20 May 2012 16:11:00 GMTServer:ASP.NET Development Server/10.0.0.0X-AspNet-Version:4.0.30319X-AspNetMvc-Version:3.0
Because the get method stores data in URLs in plaintext mode, the security is not high, and the get method can transmit up to 1024 bytes.
For Post mode, the data in the form is stored in the Header of the http request and invisible.
View:
@ {ViewBag. title = "Http Get and Post learning analysis";}
Controller:
public class StudentController : Controller { public ActionResult Add() { return View(); } [HttpPost] public ActionResult Add(string userName, string passWord) { string information = "UserName: " + userName + "Password: " + passWord; return View(); } }
Initial run:
Enter 123456 In the UserName and Password text boxes, and click the Submit button:
Next, observe the http Header:
Request URL:http://localhost:4126/Request Method:POSTStatus Code:200 OK
Request Headers:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3Accept-Encoding:gzip,deflate,sdchAccept-Language:zh-CN,zh;q=0.8Cache-Control:max-age=0Connection:keep-aliveContent-Length:31Content-Type:application/x-www-form-urlencodedHost:localhost:4126Origin:http://localhost:4126Referer:http://localhost:4126/User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19
Form Data: post-type Data storage container
userName:123456passWord:123456
Response Headers:
Cache-Control:privateConnection:CloseContent-Length:409Content-Type:text/html; charset=utf-8Date:Sun, 20 May 2012 16:27:55 GMTServer:ASP.NET Development Server/10.0.0.0X-AspNet-Version:4.0.30319X-AspNetMvc-Version:3.0
It can be seen that Post is highly secure and has a large amount of data to be transmitted. Take this note. If you have any shortcomings, please correct me.