Re: HTTP POST of json - problem

philchillbill <philchillbill.a1oq2n-NUepA2SMhDQqspMVqqL2D+4xXEVPTSb/[email protected]>
Newsgroups gmane.music.equipment.slimdevices.devel
Organization Logitech Squeezebox Forums
Message-ID <[email protected]>
Paul Webster wrote: 
> I am trying to post some json and have been trying to use
> HTTP::Request::Common
> 
> However, I think I have worked out that my problem is that the content
> is not being sent raw - instead it is being URL encoded.
> This is because HTTP::Request::Common expects the content to be a form
> of some type.
> 
> https://github.com/Logitech/slimserver/blob/359cd3a1d08a1fa86c954d1f6ac412714783522f/CPAN/HTTP/Request/Common.pm#L87
> 
> Does anyone have a pointer to some code that already does this (POST raw
> content) using Perl modules that ship with LMS?

JSON::XS::VersionOneAndTwo is standard with LMS. It provides to_json and
from_json methods. In sub -fetch_players- in
Slim::Networking::Discovery::Players.pm, you'll see an example use of
posting json using it:


Code:
--------------------
    
  	my $postdata = to_json({
  		id     => 1,
  		method => 'slim.request',
  		params => [ '', ['players', 0, 999] ]
  	});
  
  	$http->post( $url . 'jsonrpc.js', $postdata);
  
--------------------


Hope that helps


------------------------------------------------------------------------
philchillbill's Profile: http://forums.slimdevices.com/member.php?userid=68920
View this thread: http://forums.slimdevices.com/showthread.php?t=114581
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.