Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send SMS using a SMS Gateway in Android with CURL command

Status
Not open for further replies.

Ricardo.a4

IS-IT--Management
Feb 2, 2022
3
PT
Hi!
I install a SMS Gateway in a phone with android.
If a use the CURL in command line, I can send the mensages perfectly.
I try to transform this to use in Foxpro, have no luck.
Anyone can do a magic and help me?
Thanks in advance

Commandline:
curl -X POST -H "Content-Type: application/json" -H "Authorization: f3e09bbd" -d "{"to": "+351987654321", "message": "Teste envio OK"}"

FoxPro:
_comando = 'curl -X POST -H "Content-Type: application/json" -H "Authorization: f3e09bbd" -d "{"to": "987654321", "message": "Teste envio OK"}"'
msg(_comando) ShellExecute(0,"post",_comando,"","",1)
 
Ricardo,

You may try to invoke the gateway service using the WinHTTP class.

Code:
LOCAL HTTPService AS WinHttp.WinHttpRequest

m.HTTPService = CREATEOBJECT("WinHttp.WinHttpRequest.5.1")
m.HTTPService.SetRequestHeader("Content-Type", "application/json")
m.HTTPService.SetRequestHeader("Authorization", "f3e09bbd")

m.HTTPService.Open("Post", "[URL unfurl="true"]http://192.168.10.57:8082/",[/URL] .F.)

m.HTTPService.Send('{"to": "987654321", "message": "Teste envio OK"}')
 
Hi Ricardo,

looking back at my answer in thread184-1813603

You just have to add 1 and 1 together, realizing that the CURL -H options are request headers (H):
Code:
LOCAL loRequest, lcPOSTRequestbody

TEXT TO lcPOSTRequestbody NOSHOW
{"to": "987654321", "message": "Teste envio OK"}
ENDTEXT

loRequest = CREATEOBJECT("microsoft.xmlhttp")
loRequest.open("POST","[URL unfurl="true"]https://smsgateway.me/api/v4/message/send")[/URL]
loRequest.setRequestHeader("Content-Type","application/json")
loRequest.setRequestHeader("Authorization","f3e09bbd")

loRequest.send(lcPOSTRequestbody)
DO WHILE loRequest.readyState<4
   Doevents
ENDDO

? loRequest.Responsetext

What does that give you as response text?
Also, what is the response text when you don't set the Authorization header?

Chriss
 
Just by the way, you should never post real passwords or api keys or any such secrets.

So if that's real, refresh it, change it, as soon as possible, so the posted Authorization key becomes invalid.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top