HTTPS PUT method in tclcurl

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf HTTPS PUT method in tclcurl

  • Creator
    Topic
  • #55707
    Michael Vork
    Participant

    Hi all,

    Has anybody experience with the PUT method within tclcurl?

    I am calling a webservice with method POST with data in JSON format.

    With the POST method you can use parameter -postfields.

    Example:

    set msg “{“id”:”1234″,”text”:”Hello world”}”

    set ch [ curl::init ]

    set url “https://xxx.xxxxxxxxx.com/v1/aux/xxxxx

    $ch configure -post 1

    $ch configure -postfields $msg

    etc

    This works fine.

    But after that I would like to change the content of the message and update it via the PUT method.

    That should be something like this:

    set msg “{“text”:”Hello other world”}”

    set ch [ curl::init ]

    set url “https://xxx.xxxxxxxxx.com/v1/aux/xxxxx/id1234

    $ch configure -put 1

    $ch configure -postfields $msg

    etc

    At this point I cannot use the -postfields parameter.

    What alternative  for -postfields can I use to PUT the changes?

    Thanks for your response.

    Regards,

    Micha

Viewing 3 reply threads
  • Author
    Replies
    • #86240
      Levy Lazarre
      Participant

      Hi Michael,

      I have two suggestions for you:

      1. In newer versions of TclCurl, the option “-put 1” has been deprecated and replaced by “-upload 1”, so you should change to

      Code:


       $ch configure -upload 1

      2. Unlike the ‘POST’ method, ‘PUT’ does not offer the option of sending a data string, but expects a file, with indication of the file size. So you need to write your data ($msg) to a temporary file, say ‘tempfile.txt’ and complete the configuration like this:

      Code:


      $ch configure -infile tempfile.txt
      $ch configure -infilesize [file size tempfile.txt]

      I hope this helps.

    • #86241
      Rob Lindsey
      Participant

      We are running CL 6.1.1 on RHEL.

      This is how we are doing a POST to a web service.  

      Code:

      catch {
         curl::transfer -verbose 1 -userpwd $userid:$password -url $URL -header 1 -httpheader $httpHeaders -post 1 -postfields $soapMsg -bodyvar reply -errorbuffer err
      } tclerr

      Anything that gets sent back as a reply gets put into the variable   reply    

      Hope this helps.

      Rob

    • #86242
      Michael Vork
      Participant

      Hi there,

      Pretty devious this upload mechanism but it works.

      Thanks for the help.

      Regards,

      Micha

    • #86243
      Levy Lazarre
      Participant

      I agree that the upload mechanism is rather inconvenient. Here is something else to try, maybe it will work for you. Remove the upload, infile, and infilesize configs. Just use:

      Code:


      $ch configure -customrequest PUT -postfields $msg

      Let’s see what happens.

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

Forum Statistics

Registered Users
5,129
Forums
28
Topics
9,301
Replies
34,447
Topic Tags
288
Empty Topic Tags
10