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,913

    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
    Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, ABC Australia and CBC/Radio-Canada
    and, via the extra "Radio Now Playing" plugin, AllZIC Radio, Caroline Flashback, Cesky rozhlas, Dandelion Radio, Europa Radio Jazz, Frequence3, FSK, JukeRadio, KlassikRadio.de, Linn Radio, Mother Earth, Naim Radio, Nova.fr, RadioBlues Flac, Radio Espace, Radio Swiss, RTE Ireland, Somehow Jazz, Supla Finland

  2. #2
    Senior Member philchillbill's Avatar
    Join Date
    Jan 2019
    Location
    The Netherlands
    Posts
    849
    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,913
    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
    Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, ABC Australia and CBC/Radio-Canada
    and, via the extra "Radio Now Playing" plugin, AllZIC Radio, Caroline Flashback, Cesky rozhlas, Dandelion Radio, Europa Radio Jazz, Frequence3, FSK, JukeRadio, KlassikRadio.de, Linn Radio, Mother Earth, Naim Radio, Nova.fr, RadioBlues Flac, Radio Espace, Radio Swiss, RTE Ireland, Somehow Jazz, Supla Finland

Posting Permissions

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