# Confusing Http bug

**URL:** <https://discourse.elm-lang.org/t/confusing-http-bug/4342>\
**Category:** Learn\
**Created:** [September 19, 2019, 6:50pm UTC](https://discourse.elm-lang.org/t/confusing-http-bug/4342 "2019-09-19T18:50:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![psb](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/psb/32/2535_2.png) [@psb](https://discourse.elm-lang.org/u/psb)\
**Post date:** [September 19, 2019, 6:50pm UTC](https://discourse.elm-lang.org/t/confusing-http-bug/4342/1 "2019-09-19T18:50:59Z")

</div>

Hi,

I have a confusing Http bug that I am struggling to debug or work-around and I’m hoping someone can help me out.

I have a form that is submitted to the server via a `Http.request`. The form is complex and can have a video and multiple images as part of the form, so it’s a `multipart` post request; however, the simplest valid form is just with one field filled out (the ‘name’ field). So, the confusing parts:

The form with just the name field filled in does not work. The Http request gets cancelled by Elm. This is what Chrome tells me. In Firefox, the post request is not even registered in the terminal. With Chrome the data gets through to the server before the cancellation, but with Firefox it doesn’t. When the request gets cancelled, the browser (Elm?) reloads the page (a get request for the form page is registered by the server).

If I fill out any other field in the form (text, video or images) then the post request succeeds and is not cancelled. This only works if actually enter something on the form.

If I hard code a model field (a text field/input) in the Elm code to what it would be if I set it via the actual form, like above, then the request gets cancelled. The same is true if I hard code another json value alongside the name field.

I cannot `Debug.log` the Http request. I have also tried changing the request body from `multipart` to `json` if there are no videos or images, but it still fails.

`Http.post` requests seem to be getting through to the server, but I need to use `Http.request` to add headers, so it seems to be specific to `Http.request`.

Any help or insight would be greatly appreciated.

Thank you,

Paul.

---

<div class="post-metadata">

**Author:** ![Atlewee](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/atlewee/32/4603_2.png) [@Atlewee](https://discourse.elm-lang.org/u/Atlewee)\
**Post date:** [September 19, 2019, 9:26pm UTC](https://discourse.elm-lang.org/t/confusing-http-bug/4342/2 "2019-09-19T21:26:21Z")

</div>

I might be wrong, (have not used elm/html since elm-ui came abut a year ago).  
Are you using Html.form element ?  
And using Http.request on submit?  
Might the problem be that the default submit action is triggered together with your manual Http.request?  
If that is the case, I would drop using any form html element and see if that works better… (using onClick to trigger a Http.request that you have full control over)  
Or… I would ofcourse use elm-ui where the form element does not even exist 🙂

What headers do you need to set? Maybe they are not allowed… have you tried Http.riskyRequest ?

---

<div class="post-metadata">

**Author:** ![psb](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/psb/32/2535_2.png) [@psb](https://discourse.elm-lang.org/u/psb)\
**Post date:** [September 20, 2019, 9:32am UTC](https://discourse.elm-lang.org/t/confusing-http-bug/4342/3 "2019-09-20T09:32:42Z")

</div>

Thank you, @Atlewee! 👍 You were exactly right. I now remember that I developed about 95% of the form under a `div` and then changed it to a `form` later. Changing it back to a `div` has solved the problem.

And there’s me trying to be all semantic 😆

---

<div class="post-metadata">

**Author:** ![berend](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/berend/32/2250_2.png) [@berend](https://discourse.elm-lang.org/u/berend)\
**Post date:** [September 20, 2019, 9:00pm UTC](https://discourse.elm-lang.org/t/confusing-http-bug/4342/4 "2019-09-20T21:00:49Z")

</div>

Not using a form means the default Enter key won’t work, i.e. submit the form. But that might not be an issue for your form.

---

<div class="post-metadata">

**Author:** ![psb](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/psb/32/2535_2.png) [@psb](https://discourse.elm-lang.org/u/psb)\
**Post date:** [September 21, 2019, 8:47am UTC](https://discourse.elm-lang.org/t/confusing-http-bug/4342/5 "2019-09-21T08:47:27Z")

</div>

Thanks for the tip about the Enter key, @berend. It’s not really an issue for me at the moment; however, I might come back to it in the future.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [October 1, 2019, 8:47am UTC](https://discourse.elm-lang.org/t/confusing-http-bug/4342/6 "2019-10-01T08:47:40Z")

</div>

Closed on October 1, 2019, 8:47am UTC

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
