0

Heres is the relevant HTML code:

      <form id="1" action="https://hooks.nabu.casa/verylongstringofcharacterforawebhook" method="POST">
    <input name="name" value="-------">
    <button type="submit" type="button">Add to favorites</button>
    </form>
    <script>

Upon submit, the action URL is a webhook which ties to home assistant which then run a restful command which passes the data to a nodered endpoint.

The data is then saved in csv file. That seems to work. The weird part is, upon pressing submit/add to favorites, the browser starts a download for a file named

verylongstringofcharacterforawebhook

with a file size of 0mb ie blank.

Im a novice, i know enough to cause myself headaches. I cannot figure this out. Im assuming the browser thinks "/verylongstringofcharacterforawebhook" is a file, rather than a url location.

any guidance would be appreciated.

hardillb
  • 54,545
  • 11
  • 67
  • 105
Tm Win
  • 1

1 Answers1

0

This is working exactly as expected.

The browser will handle the response from the URL depending on what Headers are returned by the Server when the request is made.

It's not clear from the question if it's Home Assistant or Node-RED that is acting as the HTTP server in this case so we really can't say anything more, but if you open the browsers developer tools (normally by pressing F11) you should be able to see what Content-Encoding is being returned.

If you don't want the page to reload when you submit the form then you should look at submitting the POST request via JavaScript and a XMLHttpRequest call. This can still be triggered by the same button press, but will give you control over how to handle the response.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • The file is served up within home assistant: https://www.home-assistant.io/blog/2016/04/07/static-website/ . Node Red should be acting as an endpoint for the form only. Content encoding is not listed but conrent type is: application/x-www-form-urlencoded – Tm Win Aug 25 '22 at 22:56
  • This has nothing to do with where your HTML file is served from, it's about what is proving the end point for the POST request – hardillb Aug 25 '22 at 22:58
  • content-type is application/octet-stream. my mistake – Tm Win Aug 25 '22 at 23:01
  • Fine, but as I said the browser is doing exactly as expected. If you want to change that you have 2 choices, 1) use JavaScript as mentioned, 2) change what the server returns. With the information we have there is nothing else we can say. – hardillb Aug 25 '22 at 23:03
  • alright sounds good – Tm Win Aug 25 '22 at 23:53