FAQ
Hi
I am writing a simple test to test a POST method in a web service but my
controller does not see any content in the POSTed request.

In the controller both the $c->request->body and
$c->request->content_length are undefined.

Any ideas?

------ test.t -------
use strict;
use warnings;

use Catalyst::Test 'MyApp';
use HTTP::Request;

my $req = HTTP::Request->new(
'POST',
'/foo',
[
Content_Type => 'text/plain'
],
"hello world",
);

my $response = request($req);

-------------

Search Discussions

  • Moritz Onken at Oct 5, 2008 at 10:27 am

    Am 05.10.2008 um 10:47 schrieb Ian Docherty:

    Hi
    I am writing a simple test to test a POST method in a web service
    but my controller does not see any content in the POSTed request.

    In the controller both the $c->request->body and $c->request-
    content_length are undefined.
    Any ideas?

    ------ test.t -------
    use strict;
    use warnings;

    use Catalyst::Test 'MyApp';
    use HTTP::Request;

    my $req = HTTP::Request->new(
    'POST',
    '/foo',
    [
    Content_Type => 'text/plain'
    ],
    "hello world",
    );
    It's Content-type => ...
  • Ian Docherty at Oct 6, 2008 at 5:35 am

    Moritz Onken wrote:
    Am 05.10.2008 um 10:47 schrieb Ian Docherty:
    Hi
    I am writing a simple test to test a POST method in a web service but
    my controller does not see any content in the POSTed request.

    In the controller both the $c->request->body and
    $c->request->content_length are undefined.

    Any ideas?

    ------ test.t -------
    use strict;
    use warnings;

    use Catalyst::Test 'MyApp';
    use HTTP::Request;

    my $req = HTTP::Request->new(
    'POST',
    '/foo',
    [
    Content_Type => 'text/plain'
    ],
    "hello world",
    );
    It's Content-type => ...
    Yup, typo on my part, but it does not change the problem. There is still
    no content in the request when it gets to the controller.

    Just a slight modification to my original statement. In the controller
    the request body is undef, but the request length is 0 (not undef)

    Regards
    Ian


    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20081006/cd687192/attachment.htm
  • David Wright at Oct 6, 2008 at 8:58 am

    Ian Docherty wrote:
    Moritz Onken wrote:
    Am 05.10.2008 um 10:47 schrieb Ian Docherty:
    Hi
    I am writing a simple test to test a POST method in a web service
    but my controller does not see any content in the POSTed request.

    In the controller both the $c->request->body and
    $c->request->content_length are undefined.

    Any ideas?

    ------ test.t -------
    use strict;
    use warnings;

    use Catalyst::Test 'MyApp';
    use HTTP::Request;

    my $req = HTTP::Request->new(
    'POST',
    '/foo',
    [
    Content_Type => 'text/plain'
    ],
    "hello world",
    );
    It's Content-type => ...
    Yup, typo on my part, but it does not change the problem. There is
    still no content in the request when it gets to the controller.
    It's not a typo, the constructor accepts underscores as well as dashes
    so that you can build requests without having to quote the hash keys.
    Just a slight modification to my original statement. In the controller
    the request body is undef, but the request length is 0 (not undef)
    IIRC you have to manually add content-length yourself, HTTP::Request
    doesn't build it for you.

    Regards,
    David
  • Ian Docherty at Oct 6, 2008 at 10:46 am

    David Wright wrote:
    Ian Docherty wrote:
    Moritz Onken wrote:
    Am 05.10.2008 um 10:47 schrieb Ian Docherty:

    Hi
    I am writing a simple test to test a POST method in a web service
    but my controller does not see any content in the POSTed request.

    In the controller both the $c->request->body and
    $c->request->content_length are undefined.

    Any ideas?

    ------ test.t -------
    use strict;
    use warnings;

    use Catalyst::Test 'MyApp';
    use HTTP::Request;

    my $req = HTTP::Request->new(
    'POST',
    '/foo',
    [
    Content_Type => 'text/plain'
    ],
    "hello world",
    );
    It's Content-type => ...
    Yup, typo on my part, but it does not change the problem. There is
    still no content in the request when it gets to the controller.
    It's not a typo, the constructor accepts underscores as well as dashes
    so that you can build requests without having to quote the hash keys.

    Just a slight modification to my original statement. In the controller
    the request body is undef, but the request length is 0 (not undef)
    IIRC you have to manually add content-length yourself, HTTP::Request
    doesn't build it for you.
    Excellent. That was exactly the problem. Thanks.
    Regards,
    David


    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20081006/46a22da6/attachment.htm

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedOct 5, '08 at 9:47a
activeOct 6, '08 at 10:46a
posts5
users3
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase