According to the CURL syntax, the "-d" parameter is HTTP content body, which you can send from the OnBeginRequest event by using the "Write" or "WriteEx" method. In other words, you should modify your "OnBeginRequest" event to look something like this:
procedure TForm1.RtcDataRequest1BeginRequest(Sender: TRtcConnection);
var
Cli:TRtcDataClient absolute Sender;
MyContentBody:String;
begin
Cli.Request.FileName:='/v1/sms/messages';
Cli.Request.Host:= Cli.ServerAddr;
MyContentBody:='"{\"to\":\"$RECIPIENT_NUMBER\", \"body\":\"Hello!\"}"';
Cli.Write(MyContentBody);
end;
To make this event more generalized, since you are posting a short content and you can fill up eveything from the main thread, you can prepare all the request parameters in the main thread and use the Request.Info property to pass on the content body. For example, like this:
procedure TForm1.RtcDataRequest1BeginRequest(Sender: TRtcConnection);
var
Cli:TRtcDataClient absolute Sender;
MyContent:String;
begin
MyContent:=Cli.Request.Info.asString['body'];
Cli.Write(MyContent);
end;
procedure TForm1.RtcDataRequest1DataReceived(Sender: TRtcConnection);
var Cli:TRtcDataClient absolute Sender;
begin
if Cli.Response.Done then
begin
memo1.lines.clear;
memo1.lines.add(Cli.Read);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RtcDataRequest1.Request.Host:= rtcHttpClient1.ServerAddr;
RtcDataRequest1.Request.Method:='POST';
RtcDataRequest1.Request.FileName:='/v1/sms/messages';
RtcDataRequest1.Request['Content-Type']:='application/json';
RtcDataRequest1.Request['Authorization']:='Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXX';
RtcDataRequest1.Request.Info.asString['body']:= '"{\"to\":\"$RECIPIENT_NUMBER\", \"body\":\"Hello!\"}"';
rtcHttpClient1.Connect;
RtcDataRequest1.Post;
end;
Here is
another Forum topic with a similar question (How to POST a request).
PS. When posting "text" content, make sure to Encode it propperly, because the Write method always sends RAW data (8-bit characters), ignoring higher bits. For example, if your content is Unicode and the receiver expects the content to be UTF-8 encoded, you can use the
Utf8Encode function for encoding content to UTF-8 before sending and the
Utf8Decode function to decode the content received with UTF-8 encoding. This rule does not apply to JSON content, since it is already encoded into JSON format, which only uses 8-bit characters.
Best Regards,
Danijel Tkalcec