HTTPPost('url', '{"track": "test"}');
That seems to be sending as a parameter and not as body, I have no clue what else I can do.
Hello,
Since I could not figure this out, I’ve resorted to doing it as an argument. Now I have the issue of the song title not being URL-safe. Is there any method to make it URL-safe?
I’ve found a few Delphi methods that can do this (https://stackoverflow.com/questions/776302/standard-url-encode-function) but I’m not sure how to use these in mAirlist.
Hello @Tondose,
The method you linked would be a really hard method because I would need to account for all characters that appear in song titles.
I don’t have to put it in the URL arguments, I can also send it in the body post data of HTTPPost. But this seems to not be working and gets interpreted as form data instead of JSON.
HTTPPost('http://example.com', '{"track": "songtitle"}');
or
HTTPPost('http://example.com?track=' + current_track, '');
I have also tried HTTPPostRaw, But that seems to mess up the string.
Really all? I should say only the forbidden ones out of the 128 ASCII characters. The rest could be excluded by Ord(Character) > 128
.
Economical regards
TSD
Alright, I’ll check it out.
One other thing: How can I ignore errors in background scripts and just load them again?
And one other thing, Do you maybe have some kind of example of using that Ord command? I have 0 experience with Delphi.
You can have a look at http://www.delphibasics.co.uk/. And, for a start, here.
Ignoring errors? I probably didn’t get you right, what errors do yo mean? Errors by, say, a failed tcp-connection can be handled with the try
and except
commands. Syntax and runtime errors should be avoided anyway.
Correct regards
TSD
Hey @Tondose,
Thank you for your help! I’ve just decided to percent-encode every single character since it doesn’t really matter. I had to make a script since a lot of our at-home DJ’s were using this program and couldn’t send over a title.
// Modified from https://community.mairlist.com/t/escape-replace-characters-in-a-string/12908/4?u=dyon
function Escape(Oldstring: string): string;
var
Newstring, Part, PartUrlSafe: string;
i, PartInteger: integer;
begin
Newstring := '';
for i := 1 to Length(Oldstring) do
begin
// Get the current iteration letter
Part := Copy(Oldstring, i, 1);
// Get the according integer
PartInteger := Ord(Part[1]);
// Convert to Hex (Percent encoded)
PartUrlSafe := '%' + IntToHex(PartInteger, 2);
Newstring := Newstring + PartUrlSafe;
end;
Result := Newstring;
end;