Jump to content

Recommended Posts

Posted (edited)

Hi,

I'm failing to send Curl post command using AutoIT, basically I believe that the reason is having '!' special character in URL

I would be glad for help

; Construct JSON data
    Local $jsonData = '{"exit_status": ' & $exitStatus & ', "plugin_output": "' & $pluginOutput & '"}'

    ; Send CURL command
    Local $curlCommand = 'curl -X POST -k -H "Content-type: application/json" -H "Accept: application/json" --data "' & $jsonData & '" "https://<URL>/v1/actions/process-check-result?service=.com!passive.setEnv_check"'

 

Edited by baselz
  • Developers
Posted (edited)

Have you checked what the contents of $curlCommand is and did you think it was valid?

This runable version of your snipped:

; Construct JSON data
$exitStatus = 0
$pluginOutput = "x"
Local $jsonData = '{"exit_status": ' & $exitStatus & ', "plugin_output": "' & $pluginOutput & '"}'

; Send CURL command
Local $curlCommand = 'curl -X POST -k -H "Content-type: application/json" -H "Accept: application/json" --data "' & $jsonData & '" "https://<URL>/v1/actions/process-check-result?service=.com!passive.setEnv_check"'
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $curlCommand = ' & $curlCommand & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

give this as output:

@@ Debug(8) : $curlCommand = curl -X POST -k -H "Content-type: application/json" -H "Accept: application/json" --data "{"exit_status": 0, "plugin_output": "x"}" "https://<URL>/v1/actions/process-check-result?service=.com!passive.setEnv_check"

Doubt that this part is valid: --data "{"exit_status": 0, "plugin_output": "x"}"

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted
  On 4/25/2024 at 9:26 AM, Jos said:

Have you checked what the contents of $curlCommand is and did you think it was valid?

This runable version of your snipped:

; Construct JSON data
$exitStatus = 0
$pluginOutput = "x"
Local $jsonData = '{"exit_status": ' & $exitStatus & ', "plugin_output": "' & $pluginOutput & '"}'

; Send CURL command
Local $curlCommand = 'curl -X POST -k -H "Content-type: application/json" -H "Accept: application/json" --data "' & $jsonData & '" "https://<URL>/v1/actions/process-check-result?service=.com!passive.setEnv_check"'
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $curlCommand = ' & $curlCommand & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

give this as output:

@@ Debug(8) : $curlCommand = curl -X POST -k -H "Content-type: application/json" -H "Accept: application/json" --data "{"exit_status": 0, "plugin_output": "x"}" "https://<URL>/v1/actions/process-check-result?service=.com!passive.setEnv_check"

Doubt that this part is valid: --data "{"exit_status": 0, "plugin_output": "x"}"

Expand  

 

  On 4/25/2024 at 9:25 AM, argumentum said:

If curl runs from command line, it'll run from AutoIt. That character has nothing to do with AutoIt.

Expand  

I run curl command using this function 

Local $result = Run(@ComSpec & " /c " & $curlCommand, "", @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($result)

the Json is valid

Posted
  On 4/25/2024 at 9:28 AM, baselz said:

I run curl command using this function

Expand  

Again. If it runs well from the command line, it will do the same from a function in AutoIt but to believe that the failure is due to AutoIt is wrong.
Humor me and run it at the command prompt. Basic troubleshooting. 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

@baselz

have you tried using:

?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Developers
Posted (edited)

@baselz, No sure why you quote my post? I gave you the reason why this must be failing, and you didn't respond at all to it.
Try reading the answer again and in case you do not understand simply ask. ;) 

PS: My comment isn't about the validity of the json, but the validity of the command you have formed. Cut and Paste the full command into a CMD window and check if it works.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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
×
×
  • Create New...