Access HTTP POST request body

31 views
Skip to first unread message

Nikolay Manolov

unread,
Jan 26, 2015, 1:40:41 PM1/26/15
to nitro...@googlegroups.com
Hello,

I'm a newcomer to nitrogen and I've been fiddling with it. I have some javascript code that issues an AJAX Post. The body of the Post request contains some plain text data.
In the module that handles the request I have:
case wf_context:request_method() of
   
get -> handle_get();
    post
-> handle_post();
    _
-> wf:status_code(405)
end

handle_post
() ->
   
Body = wf:request_body(),
    io
:format("Request Body: ~p~n", [R]),
    ok
.

What i get is:

Request Body: <<>>

I saw another question asked 5 yeas back on the same topic and no conclusion was reached there. I tried
 Body = wf_context:request_bridge(),
 
Body:request_body()
but to no avail.
Just for the record the request is correctly send from the UI and received from the backend.

Jesse Gumm

unread,
Jan 26, 2015, 5:10:43 PM1/26/15
to nitrogenweb
Hi Nikolay,

Thank you for posting this. It appears to be a bug in simple_bridge's
request_body call for cowboy, as this problem does not present itself
for the other webservers (mochiweb, yaws, inets, and webmachine).

For now, I'd recommend switching your app temporarily to one of the
other servers (mochiweb or yaws ideally), and after I fix this, you
can switch back to cowboy.

Thanks, I'll get this taken care of this week,

-Jesse
> --
> You received this message because you are subscribed to the Google Groups
> "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nitrogenweb...@googlegroups.com.
> To post to this group, send email to nitro...@googlegroups.com.
> Visit this group at http://groups.google.com/group/nitrogenweb.
> For more options, visit https://groups.google.com/d/optout.



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Jesse Gumm

unread,
Jan 26, 2015, 5:12:45 PM1/26/15
to nitrogenweb
Oh, and switching to a different backend simply means:

1) Updating rebar.config to use the dependencies for the webserver
found in the .deps files here
(https://github.com/nitrogen/nitrogen/tree/master/rel/overlay)

then

2) Updating etc/simple_bridge.config's backend option to the chosen webserver

and finally,

3) running `make` from the root of your project.

-Jesse

Nikolay Manolov

unread,
Jan 26, 2015, 6:26:14 PM1/26/15
to nitro...@googlegroups.com
OK, I'll be sure to follow your advice. Thank you for the quick response.

Jesse Gumm

unread,
Jan 27, 2015, 8:53:57 PM1/27/15
to nitrogenweb
Alrighty Nikolay,

I've updated simple_bridge to properly support the request_body for
cowboy. If you switch the settings back to cowboy, and run `make
upgrade` it should recompile and things should work.

Please let me know if you continue to have troubles.

-Jesse

Nikolay Manolov

unread,
Jan 28, 2015, 2:11:50 AM1/28/15
to nitro...@googlegroups.com
Hi Jesse,

I switched back to cowboy as you mentioned and everything seems to be working well.
Thanks for your quick reaction. Good work.

-Nikolay

You received this message because you are subscribed to a topic in the Google Groups "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nitrogenweb/NY1Ub00Hnp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nitrogenweb...@googlegroups.com.

Jesse Gumm

unread,
Jan 28, 2015, 7:15:39 AM1/28/15
to nitrogenweb

Awesome! Glad that's resolved.

-Jesse

--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Reply all
Reply to author
Forward
0 new messages