Posted on August 31, 2020 at 11:52 am
Here is an example to POST JSON data with Delphi 10:
Reference: https://stackoverflow.com/a/24042633
Add these libraries in your uses:
idSSLopenSSL, idHttp, Json |
Here is the example code to POST JSON data:
procedure TForm1.Button1Click(Sender: TObject); var JsonStr: string; sResponse: string; JsonToSend: TStringStream; HTTP1: TidHTTP; F: TJSONObject; begin Button1.Enabled := False; memoResponse.Lines.Clear; memoRequest.Lines.Clear; F := TJSONObject.Create; F.AddPair('applicationId', edApplication.Text); F.AddPair('applicationPassword', edPassword.Text); F.AddPair('accountId', edAccount.Text); JsonStr := F.ToJSON; memoRequest.Text := JsonStr; JsonToSend := TStringStream.Create(JsonStr, TEncoding.UTF8); HTTP1 := TIdHTTP.Create(nil); try HTTP1.Request.ContentType := 'application/json; charset=utf-8'; HTTP1.Request.CharSet := 'utf-8'; try sResponse := HTTP1.Post(edURL.Text, JsonToSend); except on E: Exception do ShowMessage('Error on request: '#13#10 + e.Message); end; finally FreeAndNil(HTTP1); FreeAndNil(JsonToSend); FreeAndNil(F); end; memoResponse.Text := sResponse; Button1.Enabled := True; end; |
You’ll need to place OpenSSL DLLs in your application.exe folder:
libeay32.dll ssleay32.dll |
Here you can download the application source files:
Updated on September 11, 2020 at 11:15 pm
Other Posts
- Route OpenVPN Connections Through Floating IP
- How to Configure a Floating IP in a VPS (Hetzner)
- Set OpenVPN to Listed on a Specific IP Address
- Bash Trim Leading and Trailing Whitespace from a String
- Bash Get Name of Ethernet Network Interface
- VPN Providers with Dedicated Static IP Address
- OpenVPN Iptables Rules
- WireGuard VPN Iptables Rules
Updated Posts
- AMD Chipsets & Graphics Card Drivers for Windows 7, 8, 10
- AMD Radeon 7400 Drivers for Windows 10
- How to pass custom command-line parameters in InnoSetup
- Add Desktop shortcut for all Windows PC users
- Programmatically create desktop icon with InnoSetup
- GeneratePress - a Lightweight WordPress Theme 2021
- InnoSetup disable DesktopIcon via command-line
- Use cURL to authenticate with JWT Bearer tokens