I need to send raw data in the body of a POST request to a Webservice. Can I accomplish this with a HTML form?
Using a standard HTML input field seems to unavoidably generate a POST body of the form <name_of_input_field>=<DATA>
whereas I would simply like to post <DATA>
.
Do I need to resort to performing this request with javascript?
To post HTML form data to the server in URL-encoded format, you need to make an HTTP POST request to the server and provide the HTML form data in the body of the POST message. You also need to specify the data type using the Content-Type: application/x-www-form-urlencoded request header.
The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute). The form-data can be sent as URL variables (with method="get" ) or as HTTP post transaction (with method="post" ). Notes on GET: Appends form-data into the URL in name/value pairs.
Can I accomplish this with a HTML form?
No.
A form can send either application/x-www-form-urlencoded or multipart/form-data data.
If you want to use a different data format you have to start looking at JavaScript and XHR (and be subject to the Same Origin Policy and so on).
You would be better writing your server side code to accept one of the above encodings instead — there are no shortage of libraries that can decode them.
There is a potential hack here. If your data either has a natrual "=" in it, or you can modify it so that an "=" can be added in some harmless way, you can:
Source where I learned about this technique:
https://systemoverlord.com/2016/08/24/posting-json-with-an-html-form.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With