agradezco cualquier ayuda brindada!
- Code: Select all Expand view RUN
- program sendFileByUpload;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
System.Classes, System.Net.HttpClient, System.Net.Mime, System.Net.URLClient, System.Net.HttpClientComponent;
var
HttpClient: TNetHTTPClient;
Response: IHTTPResponse;
FormData: TMultipartFormData;
EndpointURL, ID_INSTANCE, API_TOKEN_INSTANCE: string;
begin
ID_INSTANCE := '110100001';
API_TOKEN_INSTANCE := 'd75b3a66374942c5b3c019c698abc2067e151558acbd451234';
EndpointURL := 'https://api.green-api.com/waInstance' + ID_INSTANCE + '/sendFileByUpload/' + API_TOKEN_INSTANCE;
HttpClient := TNetHTTPClient.Create(nil);
FormData := TMultipartFormData.Create();
FormData.AddField('chatId', '71234567890@c.us');
FormData.AddField('caption', 'test');
FormData.AddFile('file', 'C:\tmp\bp.png');
try
Response := HTTPClient.Post(EndpointURL, FormData, nil);
if Response.StatusCode = 200 then
Writeln('[Response]: ' + Response.ContentAsString)
else
Writeln('[ERROR ' + IntToStr(Response.StatusCode) + ']:' + Response.StatusText + '' + Response.ContentAsString);
readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
HttpClient.Free;
FormData.Free;
end.