FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Send sms POST
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Send sms POST
Posted: Thu Apr 06, 2023 02:40 PM

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

Marco Boschi
info@marcoboschi.it
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: Send sms POST
Posted: Thu Apr 06, 2023 03:33 PM
Hola Marco
Tal vez esto te pueda dar una luz
Yo lo uso para consumir una api
Code (fw): Select all Collapse
#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
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: Send sms POST
Posted: Thu Apr 06, 2023 03:47 PM
ON THE FIRST SHOT!

THANKYOUVERYMUCH

marco
Marco Boschi
info@marcoboschi.it
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: Send sms POST
Posted: Thu Apr 06, 2023 06:40 PM

Excelente Marco!

Me alegro haya sido de utilidad!

Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: Send sms POST
Posted: Fri Apr 07, 2023 12:44 PM
8)
Marco Boschi
info@marcoboschi.it

Continue the discussion