HTML 表单 POST 方法将“+”作为 %2B,“=”作为 %3D如何获得原始的“+”和“=”符号?

问题描述

我正在编写一个网络服务器,它可以使用 POST 方法处理从 HTML 表单 传递的数据。

我在表单中输入 c=a+b 并提交表单(点击“运行”按钮)。它看起来像:HTML page

服务器获得了 POST 请求的正文。它的身体是这样的:

code=c%3Da%2Bb

the console of server side shows the content of POST request including header and body

“c%3Da%2Bb”已编码。我必须使用一些函数将 %3D 替换为 +,将 %2B 替换为 =

我正在寻找一些方法来获取 textarea("c=a+b") 中的原始文本而不是编码文本("c%3Da%2Bb")。

我尝试通过在 HTML 表单中添加“enctype”将“内容类型”从“application/x-www-form-urlencoded”更改为“text/plain”: ''' ''' 它实际上帮助我在我的服务器中获取原始文本(“c=a+b”): the last line is body of POST request and it is the original text

但是有人说改成“text/plain”不是一个好办法。 那么有没有一种方法可以直接获取原文而不是在我的服务器端解码数据。

解决方法

这就是这种媒体类型(“application/x-www-form-urlencoded”)的工作方式。空格用“+”表示,所以“+”需要不同的编码。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...