Created
July 10, 2019 06:46
-
-
Save flydev-fr/a3940e8400a61a66e1941d7fcfb15c9b to your computer and use it in GitHub Desktop.
Send Pulseway Notification in Delphi with Indy TIdHTTP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ procedure PULSEWAY } | |
procedure TForm1.Button1Click(Sender: TObject); | |
var | |
Json: string; | |
LResponse: string; | |
JsonToSend: TStringStream; | |
begin | |
Json := '{"instance_id": "' + 'rest-v2' + | |
'","title": "' + 'MyTitle' + | |
'","message": "' + 'A simple message notification' + | |
'","priority": "' + 'critical' + | |
'"}'; | |
JsonToSend := TStringStream.Create(Json, TEncoding.UTF8); | |
try | |
IdHTTP1.Request.ContentType := 'application/json'; | |
IdHTTP1.Request.CharSet := 'utf-8'; | |
IdHTTP1.Request.CustomHeaders.FoldLines := False; | |
IdHTTP1.Request.CustomHeaders.Add('Authorization:Basic ' + TNetEncoding.Base64.Encode('login:password')); | |
try | |
LResponse := IdHTTP1.Post('https://api.pulseway.com/v2/notifications', JsonToSend); | |
except | |
on E: Exception do | |
ShowMessage('Error on request: '#13#10 + e.Message); | |
end; | |
finally | |
JsonToSend.Free; | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment