htmlformsencodingurl-encoding

HTML: prevent url-encoding of POST form


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?


Solution

  • 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