Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 3 of 3
  1. #1
    Senior Member
    Join Date
    Apr 2005
    Location
    UK/London
    Posts
    4,516

    HTTP POST of json - problem

    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/slimserv.../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?
    Paul Webster
    http://dabdig.blogspot.com
    Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, Supla Finland, ABC Australia, CBC/Radio-Canada and RTE Ireland

  2. #2
    Senior Member philchillbill's Avatar
    Join Date
    Jan 2019
    Location
    The Netherlands
    Posts
    793
    Quote Originally Posted by Paul Webster View Post
    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/slimserv.../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

  3. #3
    Senior Member
    Join Date
    Apr 2005
    Location
    UK/London
    Posts
    4,516
    Thanks - am already using the from_json/to_json methods - no problem with them.

    I'll take another look at Slim::Networking::SimpleAsyncHTTP to try to work out again why I went for Slim::Networking::Async::HTTP instead ...

    ah - the danger of borrowing code
    Paul Webster
    http://dabdig.blogspot.com
    Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, Supla Finland, ABC Australia, CBC/Radio-Canada and RTE Ireland

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •