TFPHTTPClient Daten senden mit Put (gelöst)

Alle Fragen zur Netzwerkkommunikation
Antworten
Acia6850
Beiträge: 61
Registriert: Mo 9. Okt 2023, 18:45
OS, Lazarus, FPC: Windows + WSL / Linux Debian Rasbian OS (L 3.4.0 FPC 3.2.3)
CPU-Target: 64Bit
Wohnort: LK Ludwigsburg

TFPHTTPClient Daten senden mit Put (gelöst)

Beitrag von Acia6850 »

Hallo,

wer hat schon mit dem TFPHTTPClient mit Put daten versendet
Ich kann die Daten mit get von der URL lesen aber einenPut mit Daten senden finde ich keine Beispiele.

Über Tips würde ich mich freuen.

Acia6850
Zuletzt geändert von Acia6850 am Di 10. Mär 2026, 13:12, insgesamt 1-mal geändert.

Benutzeravatar
theo
Beiträge: 11225
Registriert: Mo 11. Sep 2006, 19:01

Re: TFPHTTPClient Daten senden mit Put

Beitrag von theo »

Meinst du wirklich Put oder Post?

Acia6850
Beiträge: 61
Registriert: Mo 9. Okt 2023, 18:45
OS, Lazarus, FPC: Windows + WSL / Linux Debian Rasbian OS (L 3.4.0 FPC 3.2.3)
CPU-Target: 64Bit
Wohnort: LK Ludwigsburg

Re: TFPHTTPClient Daten senden mit Put

Beitrag von Acia6850 »

Hallo ich versuche eine Hue Bridge zu steuern.



Now let’s get information about a specific light. The light with id 1.
Address https://<bridge ip address>/api/1028d66426293e821ecfd9ef1a0731df/lights/1
Method GET

In this response you can see all of the resources this light has. The most interesting ones are inside the state object as these are the ones we’ll have to interact with to control the light.

Lets’ start with the “on” attribute. This is a very simple attribute that can have 2 values: true and false. So let’s try turning the light off.
Address https://<bridge ip address>/api/1028d66426293e821ecfd9ef1a0731df/lights/1/state
Body {"on":false}
Method PUT

Looking at the command you are sending we’re addressing the “state” object of light one and telling it to modify the “on” value inside it to false (or off). When you press the PUT button the light should turn off. Change the value in the body to true and the light will turn on again.


Link : https://developers.meethue.com/develop/get-started-2/

Ich möchte die Lampen schalten. Die Daten holen ist kein Problem.

Benutzeravatar
theo
Beiträge: 11225
Registriert: Mo 11. Sep 2006, 19:01

Re: TFPHTTPClient Daten senden mit Put

Beitrag von theo »

Ich denke du musst den zu sendenden Inhalt in RequestBody ablegen.

https://build.alb42.de/fpcbin/docu/html ... thods.html

Benutzeravatar
m.fuchs
Lazarusforum e. V.
Beiträge: 2884
Registriert: Fr 22. Sep 2006, 19:32
OS, Lazarus, FPC: Winux (Lazarus 2.0.10, FPC 3.2.0)
CPU-Target: x86, x64, arm
Wohnort: Berlin
Kontaktdaten:

Re: TFPHTTPClient Daten senden mit Put

Beitrag von m.fuchs »

Hier mal ein kleines Beispiel:

Code: Alles auswählen

program PutTest;
{$MODE ObjFpc}
{$H+}

uses
  Classes, FpHttpClient, OpenSslSockets;

var
  Client: TFPHTTPClient;
  Data: String;

begin
  // Generate Data
  Data := '{"property1":"value1", "property2":12345}';
  // Create Client
  Client := TFPHTTPClient.Create(nil);
  // Create Reqeuest Body, Write Data to Body, Set Position to Begin of Body
  Client.RequestBody := TMemoryStream.Create;
  Client.RequestBody.Write(Data[1], Length(Data));
  Client.RequestBody.Seek(0, soFromBeginning);
  // Connect to Url, Send Body via PUT
  Client.Put('https://api.example.com/data/create');
  // Print Request Answer Code
  WriteLn(Client.ResponseStatusCode, ' ', Client.ResponseStatusText);
  // Tidy up
  Client.RequestBody.Free;
  Client.Free;
end.
0118999881999119725-3

Software, Bibliotheken, Vorträge und mehr: https://www.ypa-software.de

Acia6850
Beiträge: 61
Registriert: Mo 9. Okt 2023, 18:45
OS, Lazarus, FPC: Windows + WSL / Linux Debian Rasbian OS (L 3.4.0 FPC 3.2.3)
CPU-Target: 64Bit
Wohnort: LK Ludwigsburg

TFPHTTPClient Daten senden mit Put (gelöst)

Beitrag von Acia6850 »

Vielen Dank,

für die Beispiele es läuft.

Grüße

Acia6850

Antworten