且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HTML:防止POST表单的url编码

更新时间:2023-02-25 13:33:49

不,你不能做你想做的事情。你可能不应该尝试。
事实上,你想要一个名为DATA的变量中的一些数据意味着您的POST有效内容(或您的GET查询字符串)将看起来像

 code> DATA = somevar%3Dsomeval%26somevar2%3Dsomeotherval 

如果是它就像

  DATA = somevar = someval& somevar2 = someotherval 
/ pre>

这意味着:



DATA的值为somevar = someval



somevar2的值为someotherval



这是因为每个变量的形式为VARIABLE_NAME = VALUE,并且它们是分开的通过'&'。



在你最喜欢的浏览器调试器中检查这个(我使用firebug和chrome内置的开发工具)。
所以问题是:你为什么要这么做?知道这将更容易帮助您实现您的目标。



编辑:示例是错误的


I have an HTML form which must be posted to a URL. I would like the form to POST one variable named DATA like so:

DATA: somevar=someval&somevar2=someotherval

I'm having trouble doing this. It seems by default, forms urlencode the data, resulting in:

DATA: somevar%3Dsomeval%26somevar2%3Dsomeotherval

Changing the form's enc-type to "text/plain" results in:

DATA: somevar=someval
SOMEVAR2: someotherval

Is there any way I can have a form actually just send the data as above?

No, you can't do what yo try to do. And you probably shouldn't try. The fact that you want some data inside a variable called DATA means that your POST payload (or your GET query string) will look like

DATA=somevar%3Dsomeval%26somevar2%3Dsomeotherval

If it was (as you want it to be) like

DATA=somevar=someval&somevar2=someotherval

it would mean:

DATA has a value of 'somevar=someval'

somevar2 has a value of 'someotherval'

This is because each variable has the form VARIABLE_NAME=VALUE, and they are separated by '&'.

Check this yourself in your favourite browser debugger (I use firebug and chrome built-in dev tools). So, the question is: why are you trying to do this? Knowing that it would be easier to help you achieve your goals.

EDIT: the example was wrong