HTTP之content-type相关

博客主要介绍了HTML表单中enctype的几种类型,包括application/x-www-form-urlencoded、multipart/form-data和text/plain。详细说明了不同类型下表单数据的提交情况,如application/x-www-form-urlencoded将GET方法数据放于body,multipart/form-data会加boundary划分数据等。

目录

 

application/x-www-form-urlencoded

multipart/form-data

text/plain


 

application/x-www-form-urlencoded

请求头中有content-type数据:

一般在表单中填写enctype:

其中enctype有如下的几种:

            1. application/x-www-form-urlencoded

            2. multipart/form-data

            3. text/plain

这个是浏览器自动生成的数据请求!

 

如下的HTML:

<html>
<head>
<title>优快云 IT1995</title>
</head>

<body>
<form action="/form" method="POST" enctype="application/x-www-form-urlencoded">
	<input type="text" name="name">
	<input type="password" name="password">
	<input type="submit">
</form>
</body>

</html>

运行截图如下:

填好表单后:

这里把这两个都勾上:

点击提交:

可以看到当Content-Type:application/x-www-form-urlencoded时,form表单数据如下:

点击原始后:

这个application/x-www-form-urlencoded只是把GET方法放到url中的放到body里面罢了!

 

 

multipart/form-data

把enctype修改为:multipart/form-data后,源码如下:

<html>
<head>
<title>优快云 IT1995</title>
</head>

<body>
<form action="/form" method="POST" enctype="multipart/form-data">
	<input type="text" name="name">
	<input type="password" name="password">
	<input type="submit">
</form>
</body>

</html>

再次提交表单看看:

发现浏览器默认加了一个boundary,然后在Request Payload里面,以这个为边界进行划分,并且还带上了表单的name。突然间感觉,又掉巧妙啊!

 

text/plain

把enctype修改如下:text/plain

源码如下:

<html>
<head>
<title>优快云 IT1995</title>
</head>

<body>
<form action="/form" method="POST" enctype="text/plain">
	<input type="text" name="name">
	<input type="password" name="password">
	<input type="submit">
</form>
</body>

</html>

提交表单后:

从中可以知道这个text/plain还是很常规的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT1995

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值