form里面的action和method(post和get的方法)使用

时间:2023-03-08 17:00:50

一、form里面的action和method的post使用方法

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="formsubmitpost.aspx.cs" Inherits="formsubmitpost" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server" action="formsubmitget.aspx" method="post">
<div>
<input id="b" name="b" value="" />
<input id="w" type="submit" />
</div>
</form>
</body>
</html>

当你点击button按钮提交的时候,浏览器的地址为http://localhost:1621/formsubmitpost.aspx,页面会刷新但是地址不变

二、form里面的action和method的get使用方法

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="formsubmitget.aspx.cs" Inherits="formsubmitget" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server" action="formsubmitget.aspx" method="get">
<div>
<input id="a" name="a" value="" />
<input id="w" type="submit" />
</div>
</form>
</body>
</html>

但你点击button提交的时候,浏览器地址为http://localhost:1621/formsubmitget.aspx?__VIEWSTATE=%2FwEPDwUKLTEzNDM3NzkxOWRkeBFIL8xbs6u8bVKlOO5sf6FSAk0OTJ6ZUC4n2AN9oe4%3D&a=123&__VIEWSTATEGENERATOR=4B2C1984

而这个地址包含你传过去的值。

综上,

get:

1>通过GET提交数据,用户名和密码将明文出现在URL上,因为登录页面有可能被浏览器缓存,GET请求请提交的数据放置在HTTP请求协议头

2>或者其他人查看浏览器的历史纪录,那么别人就可以拿到你的账号和密码了,除此之外,使用GET提交数据还可能会造成Cross-site request forgery攻击,所以不安全

3> GET请求有长度限制

post:

1>POST数据放在body(POST提交的数据则放在实体数据),POST请求数据不能被缓存下来

2> POST请求参数不会被保存在浏览器历史或 web 服务器日志中。

3> POST请求没有长度限制