in reply to Re: Getting error while decoding JSON object via POST method
in thread Getting error while decoding JSON object via POST method

I'm getting this exact same error when trying to access the body of an application/json POST when the request is HTTP 1.1. If it's an HTTP 1.0 request, all is fine. HTTP 1.1 requests don't set the "Content-Length" header and use "Transfer-Encoding" with a value of "chunked". Does anyone know the proper way to grab the JSON payload of a POST request that will work with both HTTP 1.0 and HTTP 1.1?
  • Comment on Re^2: Getting error while decoding JSON object via POST method

Replies are listed 'Best First'.
Re^3: Getting error while decoding JSON object via POST method
by Corion (Patriarch) on May 19, 2014 at 17:43 UTC

    Implementing a transfer encoding on the server side is not easy. I would try to prevent sending data using the "chunked" transfer encoding. Depending on your client library, there are different ways to prevent that.

      I must be missing something here. At my $work, we use CGI::Application on the front end and simply decode_json( $self->query->param( 'POSTDATA' ) ) to get the values regardless of HTTP 1.0 or HTTP 1.1 (which is what we use.) We POST with a content type of "application/json".

      It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

        No, it was me who is missing that both, client and server are under the posters control.

        I was under the wrong impression that the server was an unknown third party server.