Sending a RAW data POST-request with an HTML Form?

后端 未结 2 422
日久生厌
日久生厌 2020-12-11 01:13

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 unavoidabl

相关标签:
2条回答
  • 2020-12-11 01:43

    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.

    0 讨论(0)
  • 2020-12-11 01:48

    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:

    • Set the forms enctype to text/plain
    • Set a hidden input w/ a name taken from the start of your your data, up to but excluding the first "="
    • Set the input fields value to the byte that follows the "=" until the end of the data.

    Source where I learned about this technique:

    https://systemoverlord.com/2016/08/24/posting-json-with-an-html-form.html

    0 讨论(0)
提交回复
热议问题