[Catalyst] Testing Catalyst::Controller::REST based controllers

Ash Berlin ash_cpan at firemirror.com
Tue Feb 26 21:50:48 GMT 2008


On 26 Feb 2008, at 21:43, Damon Snyder wrote:

> Hi Ash, Everyone,
> Thanks, that seemed to move me along further. I'm still unable to  
> get the content part of the POST. I'm able to send the username and  
> password through, but for some reason my controller gets empty  
> content. Here is the request I've formed:
>
> ##### with mech object
> my $t1 = Test::WWW::Mechanize::Catalyst->new;
> $t1->add_header( 'Content-type' => 'text/x-json' );
>
> $req = new HTTP::Request ("POST", "http://localhost/rest/something",
> 						['X-Username' => 'xxxxx', 'X-Password' => 'xxxxx'],
> 						to_json({ stuff })
> 						);
> $res = $t1->request( $req );
> ### fails with my Bad Request
> #### end
>
>
> In the above request, username and password are processed  
> successfully, but no content is received.  I look for the content in  
> $c->req->data.
>
> Here is the analogous LWP request:
>
> ##### LWP object
> $ua = new LWP::UserAgent;
> $req = new HTTP::Request ("POST", "http://localhost:3000/rest/something 
> ",
> 						['X-Username' => 'xxxxx', 'X-Password' => 'xxxxx'],
> 						to_json({ stuff })
> 						);
> $req->content_type('text/x-json');
> $res = $ua->request($req);
> ### successfully creates the object
> #### end


Why not just change $ua->request there to $t1->request in your last  
snippet (i.e. set content_type on the request object, not on the mech  
object. It probably ignores it when you pass a Request object)





More information about the Catalyst mailing list