Efo74 Posted February 23, 2019 Share Posted February 23, 2019 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: expandcollapse popup;****************************************************************************************************************************** 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 :rolleyes: Link to comment Share on other sites More sharing options...
Nine Posted February 23, 2019 Share Posted February 23, 2019 Why reinventing the wheel...Take a look at it, I am currently using it successfully. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Efo74 Posted February 23, 2019 Author Share Posted February 23, 2019 I bought sms from a sms provider, and now I want to use our rest api for send sms. :rolleyes: Link to comment Share on other sites More sharing options...
TheXman Posted February 23, 2019 Share Posted February 23, 2019 @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 &= '}' CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Efo74 Posted February 23, 2019 Author Share Posted February 23, 2019 already tried ... it does not work :rolleyes: Link to comment Share on other sites More sharing options...
TheXman Posted February 23, 2019 Share Posted February 23, 2019 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? CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Efo74 Posted February 23, 2019 Author Share Posted February 23, 2019 I'm sorry . I was wrong ... it works. Thank you very much for helping :rolleyes: Link to comment Share on other sites More sharing options...
TheXman Posted February 23, 2019 Share Posted February 23, 2019 You're welcome. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Efo74 Posted February 23, 2019 Author Share Posted February 23, 2019 your help was precious, I was wrong to put the quotes before the brace and at the end :rolleyes: Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now