http reply handling

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf http reply handling

  • Creator
    Topic
  • #55506
    Alisa Kennedy
    Participant

      I need advice on how to handle HTTP replies.

      I am using CURL code to post the message to https connection.

      I need advice on how to handle http status codes returned in the reply instead of a valid acknowledgement.

    Viewing 0 reply threads
    • Author
      Replies
      • #85581
        Robert Milfajt
        Participant

          Assuming your CURL is called from a TCL program, here is a snippet from something I did to help you understand the nature of what you get back.

          First when configuring your curlHandle, include -headervar varname (sample below).  This will get you header information returned from the call in an array, including the status code, i.e., 200 (success), 400 (not found), etc.

          Code:

          set curlHandle [curl::init]
          $curlHandle configure -url $url -post 1 -postfields “$msg” -httpheader $httpHeaders -headervar httpHeader -bodyvar httpBody

          When you perform the curl call, here is an excerpt from my code which checks for curl error, then checks for success, in my example above, httpBody will contain the return from the POST, so you’re processing will vary.

          Code:

          catch { $curlHandle perform } curlErrorNumber
          if { $curlErrorNumber != 0 } {
            echo “[curl::easystrerror $curlErrorNumber]”
          } else {
            set statCode [lindex [split $httpHeader(http) ” “] 1]

            if {($statCode >= 100) && ($statCode <= 299)} {
                #successful http transfer, echo return
                regsub -all — {n} $httpBody {} ack
                set fs [string index $ack 3]
                set segs [split $ack r]
                set MSA [lindex $segs [lsearch -regexp $segs {^MSA}]]
                set ackcode [lindex [split $MSA $fs] 1]
                if {$ackcode == "AA"} {
                    echo "Successful transfer"
                    lappend dispList "KILL $mh"
                } else {
                    echo "HL7 NAK"
                    lappend dispList "ERROR $mh"
                }
            } else {
                #failed http transfer, echo code
                echo "$httpHeader(http)"
                lappend dispList "ERROR $mh"
            }
          }

          $curlHandle cleanup

          Hope this helps,

          Robert Milfajt
          Northwestern Medicine
          Chicago, IL

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