Debian Codegraph @

examples/network/put_data/put_data.dpr

raw
1 program put_data;
2
3 { Send PUT request with JSON body.
4 Note: to send non-trivial JSON, better create it with proper JSON library
5 like FpJson. }
6
7 {$apptype console}
8
9 uses
10 {$ifdef UNIX} CThreads, {$endif} // necessary to have asynchronous downloading on Unix
11 SysUtils,
12 {$ifdef FPC} OpenSSLSockets, {$endif} // support HTTPS
13 CastleUtils, CastleDownload, CastleClassUtils;
14
15 var
16 D: TCastleDownload;
17 begin
18 D := TCastleDownload.Create(nil);
19 try
20 D.Url := 'https://castle-engine.io/miscella/test_put.php';
21 D.HttpMethod := hmPut;
22 WriteStr(D.HttpRequestBody, '{ "test": "value" }');
23 D.Start;
24 D.WaitForFinish;
25 case D.Status of
26 dsError: Writeln('Error: ', D.ErrorMessage);
27 dsSuccess: Writeln('Success');
28 else raise EInternalError.Create('Unexpected status');
29 end;
30 Writeln('Response code: ', D.HttpResponseCode);
31 Writeln('Response body: ', ReadGrowingStreamToDefaultString(D.Contents));
32 finally FreeAndNil(D) end;
33 end.