Jump to content

Help convert function for send SMS


Efo74
 Share

Recommended Posts

Hello, I have a problem convert a working function that use curl command for sending sms. I would like convert it to http request. Can someone help me ?

These are the functions:

;******************************************************************************************************************************
Func SMS_Send_working($UserKey_Func,$SessionKey_Func)
;******************************************************************************************************************************
$CommandLine = 'curl -XPOST "https://internetlink/REST/sms"' & ' -H "Content-Type: application/json"' & ' -H "user_key: ' & $UserKey_Func & '"'
$CommandLine &= ' -H "Session_key: ' & $SessionKey_Func & '" ' & ' -d'
$CommandLine &= '"{'
$CommandLine &= '\"recipient\": [\"+3933812345678\"],\"message\": \"Hello world!\",\"message_type\": \"GP\",\"sender\": \"SenderName\"'
$CommandLine &= '}"'

$iPID = Run(@ComSpec & " /c " & $CommandLine,@ScriptDir,@SW_HIDE,$STDOUT_CHILD)
ProcessWaitClose($iPID)
Local $sOutput = StdoutRead($iPID)
MsgBox(0,"",$sOutput)
EndFunc
;******************************************************************************************************************************
Func SMS_Send_not_working($UserKey_Func,$SessionKey_Func)
;******************************************************************************************************************************
$Json_string =  '"{\"recipient\": [\"+3933812345678\"],'
$Json_string &= '\"message\": \"Hello world!\",'
$Json_string &= '\"message_type\": \"GP\",'
$Json_string &= '\"sender\": \"SenderName\"}"'

$objrestReq = ObjCreate("winhttp.winhttprequest.5.1")
$objrestReq.Open("POST", "https://internetlink/REST/sms", False)

$objrestReq.setRequestHeader ("Content-Type", "application/json")
$objrestReq.setRequestHeader ("user_key", $UserKey_Func)
$objrestReq.setRequestHeader ("Session_key", $SessionKey_Func)

$objrestReq.Send($Json_string)


$oReceivedText = $objrestReq.ResponseText
$oReturnCode = $objrestReq.Status

MsgBox(0,"",$oReceivedText)

Return $oReturnCode
EndFunc

Thank you for the support :ILA2:

:rolleyes:

Link to comment
Share on other sites

@Efo74

Do not escape the double quotes.

$Json_string =  '{'
$Json_string &= '"recipient": ["+3933812345678"],'
$Json_string &= '"message": "Hello world!",'
$Json_string &= '"message_type": "GP",'
$Json_string &= '"sender": "SenderName"'
$Json_string &= '}'

 

Link to comment
Share on other sites

I'm just saying that you should not escape the double quotes in your JSON string.  That was needed for the CURL command but not for the winhttp call.

As for "it doesn't work", that means absolutely nothing.  What is the specific error that you are getting? 

Link to comment
Share on other sites

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...