How do i print the request body?

I am debugging my http2-https requests that is sending a POST request with Transfer-encoding as chunked.
I want to write the whole request body to a file.

I tried with fastcgi with a php, but fastcgi will not populate post data when it is chunked. Also tired using the basic go http2 server using My journey into Go (GoLang): Day 20 - A go http/2 server example and importing httpdump utility, I am not succesful with this.

Used github.com/davecgh/go-spew/spew to dump request headers.

All these works fine when i is not a chunked request.

Any help is appreciated…

There’s not a built-in way to do this, but it looks like you are able to build from source? httputil.DumpRequest() should work fine. Be sure to pass true to the second argument.

There was a mistake. There is no concept of chunked-encoding in HTTP2.

Sorry for putting up this question here.

No problem. I didn’t even think of that :smile:

i have nginx and I am able to get the post body with the below code.

<?php $name = "tealeaf/TeaLeafData_".time().".log"; $body = file_get_contents("php://input"); file_put_contents($name, $body); ?>

The samething is not working with caddy ! wondering if there is a known reason.

Thanks,
Ravi Kumar

Is there anything in the error log ? I don’t see anything wrong with that PHP code. I’ll see if I can reproduce this.

This works fine from my test using POST and PUT.

<?php
  $body = file_get_contents("php://input");
  echo $body;
?>
1 Like

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