HTML:防止POST表单的url编码 [英] HTML: prevent url-encoding of POST form

查看:191
本文介绍了HTML:防止POST表单的url编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML表单,必须发布到一个URL。我希望表单POST一个名为DATA的变量,如下所示:

  DATA:somevar = someval& somevar2 = someotherval 

我无法做到这一点。似乎默认情况下,表单urlencode数据,导致:

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

将表单的enc-type更改为text / plain会导致:

  DATA:somevar = someval 
SOMEVAR2:someotherval

有没有办法我可以有一个表单实际上只是发送数据如上所述?

解决方案

不,你不能做你想做的事情。你可能不应该尝试。
事实上,你想要一个名为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

这篇关于HTML:防止POST表单的url编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆