HTTP Put

  • Creator
    Topic
  • #47580
    Craig Berkley
    Participant

      Anyone have any success with sending a file to a MS webserver?

    Viewing 2 reply threads
    • Author
      Replies
      • #56161
        Jesse Pangburn
        Participant

          Well, I notice you’re referring to HTTP Put, which I haven’t used.  You could try HTTP POST with the file upload syntax.  I modified an existing HTTP POST function to use “form based file upload” like in RFC 1867 using mime type multipart/form-data instead of the normal HTTP POST mime type application/x-www-form-urlencoded.

          If you’re interested in trying this, the tcl file is attached.  The function you need is “ins_BPMS_PostMsg”.  It takes a parameter url, and xml (which it posts as normal form data), and x12 which is a variable holding the contents of an X12 file (could be any file, nothign X12 specific about it).

          Anyway, if you just need to upload a file, you can use this tcl proc and strip the xml variable from it and just follow the model used for the x12 variable as your file to upload.  Your webserver needs to know what to do with the file, it doesn’t just automatically save it somewhere.  For example, you could have a servlet that read the contents of the post and saved the file upload contents to a local file, or an ASP, or whatever server side code you’re using.  I happened to use Quovadx’s BPMS which gets file upload contents into a binary handle, then you can easily tell it to save that handle as a file.  There are lots of examples on the web of server side code to handle file uploads.

          Jesse

          PS.  Well, Clovertech won’t let me add this file as an attachment, so sorry, I have to post the code inline here

          Code:


          proc ins_BPMS_PostMsg { url xml x12 } {
          set newline “x0Dx0A”
          set outputData {}
          set bound “—–NEXT_PART_[clock seconds].[pid]”
          # add the x12 file contents to the data to upload
          append outputData “–$bound${newline}Content-Disposition: form-data; name=”QDXResponseX12″; filename=”X12″;${newline}Content-Type: application/edi-x12${newline}${newline}$x12${newline}”
          # add the xml data to the data to upload
          append outputData “–$bound${newline}Content-Disposition: form-data; name=”QDXResponse”${newline}${newline}$xml${newline}”
          # add the signal that the upload is done
          append outputData “–${bound}–${newline}”

          set cfg [list [list URL $url] [list DATA $outputData]
          [list HEADERS [list
          [list CONTENT-TYPE “multipart/form-data; boundary=$bound”]]]]
          set res [httppost $cfg]
          set status [keylget res “STATUS”]
          set body [keylget res “BODY”]
          set statCode [lindex $status 1]

          # debug
          puts “CFG         IS $cfg”
          puts “STATUS      IS $status”
          puts “STATUS CODE IS $statCode”
          #puts “RESULT      IS $res”

          if {$statCode <= 299} { puts "SUCCESS HTTP POST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" puts "" puts "" return } else { puts "FAILED HTTP POST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" puts "" puts "" return [list $statCode $body] } }

        • #56162
          Craig Berkley
          Participant

            Thanks Jesse.

          • #56163
            Jesse Pangburn
            Participant

              OK, then I suggest you search for “form based file upload” or “rfc 1867”, and you will definitely find ASP code for handling the file save from this tcl proc.

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