tclcurl and json POST

Clovertech Forums Read Only Archives Cloverleaf General tclcurl and json POST

  • Creator
    Topic
  • #55434
    Dennis Pfeifer
    Participant

      Not Cloverleaf related.

      Has anyone used tclcurl with JSON (and REST)?

      I’m looking to replicate something similar to

      /hci/cis6.2/integrator/bin/curl -s -H “Content-Type: application/json” -x proxy:3128 -u XX:XX -X POST -d {“send_activation_email”: false  } https://jsontest.test.com/test

      I can use curl, but not sure how to do the same with tclcurl.

      The -d option is stumping me. If using POST protocol, tcllib wants to help me and send data in the ‘normal’ POST format.

    Viewing 2 reply threads
    • Author
      Replies
      • #85315
        bill bearden
        Participant

          What do you mean by “‘normal’ POST format?

          Are you just saying your JSON is missing the open and close curly braces? Or what?

        • #85316
          Jeff Anderson
          Participant

            Here is how I do it:

                   set url “http://webservice-site”;

                   set typ “application/json”

                   set ch [ curl::init ]

                   $ch configure -post 1

                   $ch configure -postfields

                     $ch configure -url $url

                     $ch configure -httpheader [ list “Content-Type: $typ” “authToken:$tokval” ]

                     $ch configure -bodyvar pdfData

                     catch { $ch perform  } returnCode

              Hope this helps,

              Jeff

          • #85317
            bill bearden
            Participant

              Similar to Jeff but specific to JSON, something like

              Code:


              package require TclCurl
              package require json::write

              set URL “http://yourhostname:4949/”
              set HttpHeader [list]
              lappend HttpHeader “Content-Type: text/json”
              set PostBody [::json::write object send_activation_email false]

              set JSONResponse “”
              set ReturnCode “”

              set ReturnCode [curl::transfer -url $URL
                             -post 1
                             -httpheader $HttpHeader
                             -postfields $PostBody
                             -bodyvar JSONResponse]

              produces something like

              Code:


              POST / HTTP/1.1
              Host: yourhostname:4949
              Accept: */*
              Content-Type: text/json
              Content-Length: 39

              {
                 “send_activation_email” : false
              }

          Viewing 2 reply threads
          • The forum ‘General’ is closed to new topics and replies.