本文摘自PHP中文网,作者不言,侵删。
从POST表单发送数据时,它具有以下格式:(input字段的name)=(input字段的值)是用&连接的形式。空格和非ASCII字符(如中文)是URL编码和发送的。
(input字段1的name)=(input字段1的值)&(input字段2的name)=(input字段2的值)&...
我们来看具体的代码
PostForm.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <!DOCTYPE html>
< html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" />
< title ></ title >
</ head >
< body >
< form method = "post" action = "PostDest.aspx" >
< div >Value-01< input name = "value01" type = "text" /></ div >
< div >Value-02< input name = "value02" type = "text" /></ div >
< div >Value-03
< select id = "Select1" name = "value03" >
< option >元素1</ option >
< option >元素2</ option >
< option >元素3</ option >
< option >元素4</ option >
< option >元素5</ option >
</ select >
</ div >
< div >Value-04< br />
< input id = "Radio1" name = "RadioGroup1" type = "radio" />< label for = "Radio1" >单选按钮 元素1</ label >< br />
< input id = "Radio2" name = "RadioGroup1" type = "radio" />< label for = "Radio2" >单选按钮 元素2</ label >< br />
< input id = "Radio3" name = "RadioGroup1" type = "radio" />< label for = "Radio3" >单选按钮 元素3</ label >< br />
</ div >
< div >Value-05< br />
< input id = "Chkbox1" name = "checkbox1" type = "checkbox" />< label for = "Checkbox1" >检查项目1</ label >< br />
</ div >
< div >Value-06< br />
< input id = "Hidden1" name = "hiddenfield1" type = "hidden" value = "Test Value" />< br />
</ div >
< input type = "submit" value = "POST" />
</ form >
</ body >
</ html >
|
说明:
带有HTML的form标签的表单。通过设置method =“post”来POST表单数据。POST的目标URL由action =“PostDest.aspx”指定。如果未指定,将对同一URL执行POST。
服务器端
服务器端接收POSTed数据并将其显示,下面使用ASP.NET来构建它。
PostDest.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PostDest.aspx.cs" Inherits="HtmlForm.PostDest" %>
<!DOCTYPE html>
< html >
< head runat = "server" >
< meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" />
< title ></ title >
</ head >
< body >
< form id = "form1" runat = "server" >
< div >
< asp:Label ID = "Label1" runat = "server" Text = "Label" ></ asp:Label >
</ div >
</ form >
</ body >
</ html >
|
PostDest.aspx.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace HtmlForm
{
public partial class PostDest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StreamReader reader = new StreamReader(Request.InputStream);
string str = reader.ReadToEnd();
reader.Close();
Label 1 .Text = str;
}
}
}
|
运行结果:在浏览器上将显示如下所示效果
在文本框或每个字段中输入值。输入后,单击[POST]按钮。
最后,发送到服务器的POST数据将显示在浏览器页面上。
以上就是通过POST从HTML表单发送数据的格式(附代码)的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
什么是HTML表单
html制作登录表单
HTML表单的基本元素
通过post从HTML表单发送数据的格式(附代码)
更多相关阅读请进入《HTML表单》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » 通过POST从HTML表单发送数据的格式(附代码)