Page 1 of 1
Send sms POST
Posted: Thu Apr 06, 2023 2:40 pm
by MarcoBoschi
Hi to all!
I have to send sms from my application in this way Using Rest Api of our provider.
Using this command from ubuntu (in my windows10) it works fine
curl --location 'https://app.xxxxxxx.it/API/v1.0/REST/sms' \
--header 'user_key: 9999999' \
--header 'Access_token: TOKENALFANUMERICO' \
--header 'Content-Type: application/json' \
--data '{
"recipient": [
"+393123456789"
],
"message": "Ths is a Test",
"sender": "MarcoBoschi",
"message_type": "n"
}'
How can I launch this command from a fivewin program?
Many Thanks to all
Marco
Re: Send sms POST
Posted: Thu Apr 06, 2023 3:33 pm
by cmsoft
Hola Marco
Tal vez esto te pueda dar una luz
Yo lo uso para consumir una api
Code: Select all | Expand
#include "Fivewin.ch"
static oOle
FUNCTION Main()
LOCAL aData, cJson, cContentType, aResp, aAuthorization, aRecipient := {}
Try
//oOle := CreateObject( 'MSXML2.XMLHTTP' )
oOle := Createobject("MSXML2.ServerXMLHTTP")
Catch
oOle := CreateObject( 'Microsoft.XMLHTTP' )
End
aData := hash()
AADD(aRecipient,'+393123456789')
aData["recipient"] = aRecipient
aData["message"] = "Ths is a Test"
aData["sender"] = "MarcoBoschi"
aData["message_type"] = "n"
aAuthorization := {{"user_key","9999999"},{"Access_token","TOKENALFANUMERICO"}}
cJson := hb_jsonEncode(aData,.f.)
cContentType:="application/json"
aResp := SendPostToUrl( "https://app.xxxxxxx.it/API/v1.0/REST/sms", cJson, cContentType, aAuthorization )
if valtype(aResp) == 'C'
MsgInfo(aResp)
Else
xbrowse(aResp) // Ver respuesta
endif
Return NIL
STATIC Function SendPostToUrl( cUrl, cParams,cContentType,aAuthorization )
Local cRet:='',uRet, i, oError
default cContentType:="application/json"
default aAuthorization:={}
oOle:Open( 'POST', cUrl, .f. )
if !empty(aAuthorization)
for i := 1 TO len(aAuthorization)
oOle:SetRequestHeader( aAuthorization[i,1],aAuthorization[i,2])
next i
endif
oOle:SetRequestHeader( "Content-Type",cContentType)
try
oOle:Send( cParams )
Catch oError
MsgInfo(oError:description)
return "Error"
end try
cRet:=""
IF !oOle:ResponseBody = NIL
hb_jsonDecode(oOle:ResponseBody,@cRet)
ELSE
cRet := oOle:ResponseText
ENDIF
Return cRet
Re: Send sms POST
Posted: Thu Apr 06, 2023 3:47 pm
by MarcoBoschi
ON THE FIRST SHOT!
THANKYOUVERYMUCH
marco
Re: Send sms POST
Posted: Thu Apr 06, 2023 6:40 pm
by cmsoft
Excelente Marco!
Me alegro haya sido de utilidad!
Re: Send sms POST
Posted: Fri Apr 07, 2023 12:44 pm
by MarcoBoschi