It sounds like you might be trying to do a "cross-domain" post, i.e. are you running your elm app on one port, and attempting to POST to another port? If so, this is considered "cross-domain". (Of course, if you have an IP address or domain that's different, that's "cross-domain" as well).
If this is the case, then you need to enable CORS requests on the receiving domain. CORS is a way of negotiating access on a server at another "domain" (or port) so that the server can be responsible for accepting or denying AJAX requests from around the internet. One of the steps that occurs during that negotiation is an OPTIONS header request. Does that help? Duane On Wed, Jan 18, 2017 at 1:33 AM, <beye...@gmail.com> wrote: > I'm trying to use elm-lang/http without success so far. I want to address > an API with a POST request via JSON. All my efforts so far result in having > the wrong headers. > > There are two things I've tried in the following: in both cases the server > tells me that it wasn't a POST request but OPTIONS. > > I've tried using "Http.post": > > jsonify : String -> Http.Body > jsonify str = > Http.jsonBody <| Encode.object [("sentiment", Encode.string str)] > > > decodeJson : Decode.Decoder String > decodeJson = > Decode.map2 (\classification status -> classification) > (Decode.field "classification" Decode.string) > (Decode.field "status" Decode.int) > > > fetchSentiment : String -> Cmd Msg > fetchSentiment sentiment = > Http.send Fetch (Http.post (jsonify sentiment) decodeJson) > > and a custom request: > > fetchSentiment : String -> Cmd Msg > fetchSentiment sentiment = > Http.send Fetch (postSentiment sentiment decodeJson) > > postSentiment : String -> Decode.Decoder String -> Http.Request String > postSentiment sentiment decoder = > Http.request > { method = "POST" > , headers = [(Http.header "Content-Type" "application/json")] > , url = "http://127.0.0.1:5000/sentiment" > , body = (jsonify sentiment) > , expect = Http.expectJson decoder > , timeout = Nothing > , withCredentials = False > } > > Is my problem related to the code above, and if so, how can I fix it? > > -- > You received this message because you are subscribed to the Google Groups > "Elm Discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to elm-discuss+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.