mofareh 2 Posted September 12, 2022 the code is vb.net ... i want to write it by delphi Sub Main(filename As String, MassegeTxt As String, mobileNo As String) ''''' send image as base64 Dim WebRequest As HttpWebRequest Dim bytes As Byte() = IO.File.ReadAllBytes(filename) Dim file As String = Convert.ToBase64String(bytes) 'Dim mof As String = HttpUtility.UrlEncode(file) Dim instance_id As String = "instance xxxxx" Dim token As String = "xxxxxxx" Dim mobile_number As String = mobileNo WebRequest = HttpWebRequest.Create("https://api.ultramsg.com/" + instance_id + "/messages/image") Dim postdata As String = "token=" + token + "&to=" + mobileNo + "&image=" & HttpUtility.UrlEncode(file) & "&caption=" + MassegeTxt Dim enc As UTF8Encoding = New System.Text.UTF8Encoding() Dim postdatabytes As Byte() = enc.GetBytes(postdata) WebRequest.Method = "POST" WebRequest.ContentType = "application/x-www-form-urlencoded" WebRequest.GetRequestStream().Write(postdatabytes) Dim ret As New System.IO.StreamReader(WebRequest.GetResponse().GetResponseStream()) Console.WriteLine(ret.ReadToEnd()) End Sub Share this post Link to post
David Heffernan 2345 Posted September 12, 2022 (edited) What is stopping you from writing this in Delphi? I don't fully understand the question? Do you have any programmers on your team? Why not ask one of them to do this? Edited September 12, 2022 by David Heffernan Share this post Link to post
mofareh 2 Posted September 12, 2022 (edited) 10 minutes ago, David Heffernan said: What is stopping you from writing this in Delphi? I don't fully understand the question? Do you have any programmers on your team? Why not ask one of them to do this? i dont know the vb.net i need any devlober write code by vb.net and delphi we dont have team we small busnse Edited September 12, 2022 by mofareh Share this post Link to post
David Heffernan 2345 Posted September 12, 2022 Don't you have any software developers? Share this post Link to post
mofareh 2 Posted September 12, 2022 3 minutes ago, David Heffernan said: Don't you have any software developers? I am delphi developer but i want helping Help me or stop question Share this post Link to post
mvanrijnen 123 Posted September 12, 2022 (edited) you gonna need more then that code translated to delphi, Probably there will be some authentication/authorisation) things needed before you can post your data. ah, another WhatsApp api, see here tuturioals enough for other languages: WhatsApp API gateway for sending messages and chatbot - Ultramsg Edited September 12, 2022 by mvanrijnen Share this post Link to post
mvanrijnen 123 Posted September 12, 2022 (edited) 14 minutes ago, mofareh said: I am delphi developer . In that case, the code is not that difficult, as a Delphi developer you have to be able to do this for 99,9% on your own. So make your own code in Delphi, see if it works, if it doesn't, then post that Delphi code here for reviewing/tips/improvements. Edited September 12, 2022 by mvanrijnen 2 Share this post Link to post
Remy Lebeau 1394 Posted September 12, 2022 3 hours ago, mofareh said: the code is vb.net ... i want to write it by delphi If you are using Indy, the code would look something like this: uses ..., System.Classes, IdCoderMIME, IdHTTP, System.IOUtils; procedure Main(const filename, MassegeTxt, mobileNo: String); var WebRequest: TIdHTTP; SSL: TIdSSLIOHandlerSocketOpenSSL; bytes: TBytes; file: String; instance_id: String; token: String; mobile_number: String; postdata: TStringList; begin // send image as base64 bytes := TFile.ReadAllBytes(filename); file := TIdEncoderMIME.EncodeBytes(bytes); instance_id := 'instance xxxxx'; token := 'xxxxxxx'; mobile_number := mobileNo; WebRequest := TIdHTTP.Create; try SSL := TIdSSLIOHandlerSocketOpenSSL.Create(WebRequest); SSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2]; WebRequest.IOHandler := SSL; WebRequest.Request.ContentType := 'application/x-www-form-urlencoded'; postdata := TStringList.Create; try postdata.Add('token=' + token); postdata.Add('to=' + mobileNo); postdata.Add('image=' + file); postdata.Add('caption=' + MassegeTxt); Writeln(WebRequest.Post('https://api.ultramsg.com/' + instance_id + '/messages/image', postdata)); finally postdata.Free; end; finally WebRequest.Free; end; end; If you want to use Embarcadero's TNetHTTPClient, the code would look something like this instead: uses ..., System.Classes, System.SysUtils, System.NetEncoding, System.Net.HTTPClientComponent, System.IOUtils; procedure Main(const filename, MassegeTxt, mobileNo: String); var WebClient: TNetHTTPClient; bytes: TBytes; file: String; instance_id: String; token: String; mobile_number: String; postdata: TStringList; begin // send image as base64 bytes := TFile.ReadAllBytes(filename); file := TNetEncoding.Base64.EncodeBytesToString(bytes); instance_id := 'instance xxxxx'; token := 'xxxxxxx'; mobile_number := mobileNo; WebClient := TNetHTTPClient.Create(nil); try WebClient.ContentType := 'application/x-www-form-urlencoded'; postdata := TStringList.Create; try postdata.Add('token=' + token); postdata.Add('to=' + mobileNo); postdata.Add('image=' + file); postdata.Add('caption=' + MassegeTxt); Writeln(WebClient.Post('https://api.ultramsg.com/' + instance_id + '/messages/image', postdata, nil, TEncoding.UTF8, nil).ContentAsString()); finally postdata.Free; end; finally WebClient.Free; end; end; Or, using Embarcadero's THTTPClient instead: uses ..., System.Classes, System.SysUtils, System.IOUtils, System.NetEncoding, System.Net.HttpClient; procedure Main(const filename, MassegeTxt, mobileNo: String); var WebClient: THTTPClient; bytes: TBytes; file: String; instance_id: String; token: String; mobile_number: String; postdata: TStringList; begin // send image as base64 bytes := TFile.ReadAllBytes(filename); file := TNetEncoding.Base64.EncodeBytesToString(bytes); instance_id := 'instance xxxxx'; token := 'xxxxxxx'; mobile_number := mobileNo; WebClient := THTTPClient.Create; try WebClient.ContentType := 'application/x-www-form-urlencoded'; postdata := TStringList.Create; try postdata.Add('token=' + token); postdata.Add('to=' + mobileNo); postdata.Add('image=' + file); postdata.Add('caption=' + MassegeTxt); Writeln(WebClient.Post('https://api.ultramsg.com/' + instance_id + '/messages/image', postdata, nil, TEncoding.UTF8, nil).ContentAsString()); finally postdata.Free; end; finally WebClient.Free; end; end; 1 Share this post Link to post
mvanrijnen 123 Posted September 12, 2022 (edited) ..... or you ask Remy 🙂 Edited September 12, 2022 by mvanrijnen 1 1 Share this post Link to post
mofareh 2 Posted September 12, 2022 1 hour ago, Remy Lebeau said: If you are using Indy, the code would look something like this: uses ..., System.Classes, IdCoderMIME, IdHTTP, System.IOUtils; procedure Main(const filename, MassegeTxt, mobileNo: String); var WebRequest: TIdHTTP; SSL: TIdSSLIOHandlerSocketOpenSSL; bytes: TBytes; file: String; instance_id: String; token: String; mobile_number: String; postdata: TStringList; begin // send image as base64 bytes := TFile.ReadAllBytes(filename); file := TIdEncoderMIME.EncodeBytes(bytes); instance_id := 'instance xxxxx'; token := 'xxxxxxx'; mobile_number := mobileNo; WebRequest := TIdHTTP.Create; try SSL := TIdSSLIOHandlerSocketOpenSSL.Create(WebRequest); SSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2]; WebRequest.IOHandler := SSL; WebRequest.Request.ContentType := 'application/x-www-form-urlencoded'; postdata := TStringList.Create; try postdata.Add('token=' + token); postdata.Add('to=' + mobileNo); postdata.Add('image=' + file); postdata.Add('caption=' + MassegeTxt); Writeln(WebRequest.Post('https://api.ultramsg.com/' + instance_id + '/messages/image', postdata)); finally postdata.Free; end; finally WebRequest.Free; end; end; If you want to use Embarcadero's TNetHTTPClient, the code would look something like this instead: uses ..., System.Classes, System.SysUtils, System.NetEncoding, System.Net.HTTPClientComponent, System.IOUtils; procedure Main(const filename, MassegeTxt, mobileNo: String); var WebClient: TNetHTTPClient; bytes: TBytes; file: String; instance_id: String; token: String; mobile_number: String; postdata: TStringList; begin // send image as base64 bytes := TFile.ReadAllBytes(filename); file := TNetEncoding.Base64.EncodeBytesToString(bytes); instance_id := 'instance xxxxx'; token := 'xxxxxxx'; mobile_number := mobileNo; WebClient := TNetHTTPClient.Create(nil); try WebClient.ContentType := 'application/x-www-form-urlencoded'; postdata := TStringList.Create; try postdata.Add('token=' + token); postdata.Add('to=' + mobileNo); postdata.Add('image=' + file); postdata.Add('caption=' + MassegeTxt); Writeln(WebClient.Post('https://api.ultramsg.com/' + instance_id + '/messages/image', postdata, nil, TEncoding.UTF8, nil).ContentAsString()); finally postdata.Free; end; finally WebClient.Free; end; end; Or, using Embarcadero's THTTPClient instead: uses ..., System.Classes, System.SysUtils, System.IOUtils, System.NetEncoding, System.Net.HttpClient; procedure Main(const filename, MassegeTxt, mobileNo: String); var WebClient: THTTPClient; bytes: TBytes; file: String; instance_id: String; token: String; mobile_number: String; postdata: TStringList; begin // send image as base64 bytes := TFile.ReadAllBytes(filename); file := TNetEncoding.Base64.EncodeBytesToString(bytes); instance_id := 'instance xxxxx'; token := 'xxxxxxx'; mobile_number := mobileNo; WebClient := THTTPClient.Create; try WebClient.ContentType := 'application/x-www-form-urlencoded'; postdata := TStringList.Create; try postdata.Add('token=' + token); postdata.Add('to=' + mobileNo); postdata.Add('image=' + file); postdata.Add('caption=' + MassegeTxt); Writeln(WebClient.Post('https://api.ultramsg.com/' + instance_id + '/messages/image', postdata, nil, TEncoding.UTF8, nil).ContentAsString()); finally postdata.Free; end; finally WebClient.Free; end; end; How can I thank you?? The code is post correctly Thank you very much Share this post Link to post
Lars Fosdal 1792 Posted September 13, 2022 13 hours ago, mofareh said: How can I thank you?? Well, not quoting the entire post would be good start... 1 1 Share this post Link to post