Welcome! Log In Create A New Profile

Advanced

Re: Trouble getting the Request Body of a HTTP Post

February 08, 2011 06:38PM
Great discussion even though this was posted a year ago! I was looking for information on capturing the POST request body and this cleared things up quite a bit on what is going on under the hood. My problem is slightly different in that I just want to log the request body.

I have my config setup to handle a bunch of GET requests which render pixels that work fine to handle analytics and parse query strings for logging. With an additional third party data stream, I need to handle a POST request to a given url that has JSON in an expected loggable format inside of it's request body. I don't want to use a secondary server with proxy_pass and just want to log the whole response into an associated log file like what it does with GET requests. A snippet of some code that I'm using looks like the following:

GET request (which works great):

[code]
location ^~ /rl.gif {
set $rl_lcid $arg_lcid;
if ($http_cookie ~* "lcid=(.*\S)")
{
set $rl_lcid $cookie_lcid;
}

empty_gif;
log_format my_tracking '{ "guid" : "$rl_lcid", "data" : "$arg__rlcdnsegs" }';
access_log /mnt/logs/nginx/my.access.log my_tracking;
rewrite ^(.*)$ http://my/url?id=$cookie_lcid? redirect;
}
[/code]



Here is kinda what I am trying to do:
POST request (which does not work):

[code]
location /bk {
log_format bk_tracking $request_body;
access_log /mnt/logs/nginx/bk.access.log bk_tracking;
}
[/code]



Curling "curl http://myurl/bk -d name=example" gives me a 404 page not found.

Then I tried:

[code]
location /bk.gif {
empty_gif;
log_format bk_tracking $request_body;
access_log /mnt/logs/nginx/bk.access.log bk_tracking;
}
[/code]


Curling "curl http://myurl/bk.gif -d name=example" gives me a 405 Not Allowed.

My current version is nginx/0.7.62. Any help in the right direction is very much appreciated! Thanks!
Subject Author Posted

Trouble getting the Request Body of a HTTP Post

Tronman December 17, 2009 11:35AM

Re: Trouble getting the Request Body of a HTTP Post

Maxim Dounin December 17, 2009 12:44PM

Re: Trouble getting the Request Body of a HTTP Post

Tronman December 17, 2009 01:58PM

Re: Trouble getting the Request Body of a HTTP Post

Tronman December 17, 2009 02:28PM

Re: Trouble getting the Request Body of a HTTP Post

Maxim Dounin December 17, 2009 02:32PM

Re: Trouble getting the Request Body of a HTTP Post

Tronman December 17, 2009 03:33PM

Re: Trouble getting the Request Body of a HTTP Post

barretto_chris February 08, 2011 06:38PM

Re: Trouble getting the Request Body of a HTTP Post

Nick Pearson December 17, 2009 03:50PM

Re: Trouble getting the Request Body of a HTTP Post

Maxim Dounin December 17, 2009 05:02PM

Re: Trouble getting the Request Body of a HTTP Post

Tronman December 18, 2009 08:32AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 319
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready