Format for HTTP REST GET commands

Forum to ask for any help
Post Reply
mvppsu
Posts: 4
Joined: Thu Aug 22, 2019 2:31 am

Format for HTTP REST GET commands

Post by mvppsu » Fri Sep 13, 2019 6:22 am

I'm using REST commands to control my SONOS system via the SONOS HTTP API (https://github.com/jishi/node-sonos-http-api). I utilize feedback from the SONOS system to populate a list of Favorite Stations. I then create commands that send a request to play one of the stations.

My problem is that using DemoPad to send the GET commands requires the command be formatted like this:

GET /RoomName/favorite/Station%20XYZ HTTP/1.0\x0D\x0A
vs
GET /RoomName/favorite/Station XYZ HTTP/1.0\x0D\x0A

When I test using Postman the %20 is not required. The problem is that I want to dynamically insert the Favorite Station name based on feedback I receive from SONOS that tells me what the favorite stations are. And the feedback has a space instead of %20.

It looks something like this:

LABELS Created from Feedback
Favorite 1 = Station XYZ
Favorite 2 = Station ABC
Favorite 3 = Station 3

Commands
Play Favorite 1 = GET /RoomName/favorite/[Favorite 1] HTTP/1.0\x0D\x0A

However the Play Favorite command does not work because it trys to send a command with a space between "Station" and "XYZ" instead of a "%20".

Does anyone know of a solution? A way to get DemoPad to format the message in a way that does not require the %20 to be manually added? or a way to add the %20 into the variable "Favorite 1"?

ask4mikie
Posts: 12
Joined: Fri Nov 15, 2013 3:54 am

Re: Format for HTTP REST GET commands

Post by ask4mikie » Tue Oct 08, 2019 12:09 am

%20 is ascii for space.

Try replacing it with \x20.

mvppsu
Posts: 4
Joined: Thu Aug 22, 2019 2:31 am

Re: Format for HTTP REST GET commands

Post by mvppsu » Mon Jan 11, 2021 7:15 am

Anyone able to figure this out? I have the same issue trying to control my SONOS via the HTTP REST API.

DemoPad Command:
GET /[SONOS Selected Zone]/favorite/[Favorites 1] HTTP/1.1\x0D\x0AHost: 192.168.20.116:5005\x0D\x0A

Where [SONOS Selected Zone] and [Favorites 1] are Label Variables.


Captured with Hercules, below is the difference between what DemoPad sends and what is sent by a web browser.

DemoPad:
GET /theater/favorite/Against The Wind Radio HTTP/1.1
Host: 192.168.20.116:5005

Firefox:
GET /theater/favorite/Against%20The%20Wind%20Radio HTTP/1.1
Host: 192.168.20.116:5005
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1

User avatar
DemoPad
Site Admin
Posts: 764
Joined: Thu Jun 14, 2012 10:46 am
Contact:

Re: Format for HTTP REST GET commands

Post by DemoPad » Mon Jan 11, 2021 5:46 pm

When forming a url, you need to use $20 for spaces, which is the problem, as your retrieved feedback will contain actual space characters which are invalid url characters.

In the next version of the CentroControl app, the 'send data to website' action type (which you can use for GET requests requiring no feedback) automatically converts spaces to $20.

Post Reply