Skip to content

Instantly share code, notes, and snippets.

@an01f01
Created May 19, 2022 18:32
Show Gist options
  • Save an01f01/b16f0133e9d9b4db0c963af100325f0f to your computer and use it in GitHub Desktop.
Save an01f01/b16f0133e9d9b4db0c963af100325f0f to your computer and use it in GitHub Desktop.
A free pascal sample post procedure in a TForm
procedure TForm1.OnPost(Sender: TObject);
begin
{ Translate text test }
httpClient := TFPHTTPClient.Create(nil);
httpClient.RequestBody := TRawByteStringStream.Create(Memo1.Text);
ResponseRest := TStringStream.Create('');
try
try
httpClient.Post('<REPLACE WITH YOUR URL TO REST POST API>', ResponseRest);
Memo2.Lines.Add('Response Code is ' + inttostr(httpClient.ResponseStatusCode));
Memo2.Lines.Add(httpClient.ResponseStatusText);
Memo2.Lines.Add(ResponseRest.DataString);
except on E:Exception do
Memo2.Lines.Add('something bad happened : ' + E.Message);
end;
finally
httpClient.RequestBody.Free;
httpClient.Free;
end;
end;
@an01f01
Copy link
Author

an01f01 commented May 19, 2022

{
"to": "ja",
"from": "en",
"audio": false,
"text": "this is my name"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment