4 Replies Latest reply on Aug 29, 2016 8:30 AM by deninger

    Best Way to POST with a COOKIE

    deninger

      I have to be able to POST to a Restful web service and the curl statement that represents what I need to do is this:

       

      curl -i -X POST -H "Content-Type: application/json" --cookie "iPlanetDirectoryPro=AQI....A3*" https://abc.def.ghi.com/qa/cpscert/apienrollment/rest/v1/json/message/enrollment -d @/path/to/data.json

       

      I have been able to POST via several different methods in the past, including

       

      1) MBS Plugin

      2) Base Elements Plugin

      3) custom PHP using CURL

       

      I have also toyed with simply trying to send the command line CURL, but platform differences might make this difficult and I do need the result of the CURL returned to the solution...

       

      My struggle here is attaching the cookie information to the POST. I have tried a all three above without success. I believe that the difficulty stems from the difference between how the command line CURL command handles the cookie (the --cookie "data=value" works fine there) compared to implementations in PHP, MPB Plugin and the Base Elements Plugin.

       

      Would anyone be able to "translate" the above CURL command to a FM Pro usable version using one or more of the available mechanisms? The return result (form the CURL command is important to me and needs to be captures back into the Filemaker solution).

        • 1. Re: Best Way to POST with a COOKIE
          David Moyer

          Hi,

          I hope this is helpful.  I use the following calculation to build a URL that I use with the Insert From URL script step and my own web service.  The Insert populates whatever text field you pick with the response from the web service.  I receive an XML response.

          $url =

          "httppost://localhost:49924/ImageService.asmx/ChunkThisRectangle?" &

          "method=post" &

          "&countWide=" & $$puzzleWidth &

          "&countHigh=" & $$puzzleHeight &

          "&path=" & $sourceImagePath

           

          (I'm not certain that the "method" parameter is required.)

          • 2. Re: Best Way to POST with a COOKIE
            monkeybreadsoftware

            What did you try with MBS Plugins?

            You should be able to pass the cookie text to CURL.SetOptionCookie function.

            • 3. Re: Best Way to POST with a COOKIE
              monkeybreadsoftware

              Maybe like this:

               

              #Start new session

              Set Variable [$curl; Value:MBS("CURL.New")]

              Set Variable [$result; Value:MBS("CURL.SetOptionURL"; $curl; "https://community.filemaker.com/external-link.jspa?url=https%3A%2F%2Fabc.def.ghi.com%2Fqa%2Fcpscert%2Fapienrollment%2Frest%2Fv1%2Fjson%2Fmessage%2Fenrollment")]

              Set Variable [$result; Value:MBS("CURL.SetOptionHTTPHeader"; $curl; "Content-Type: application/json")]

              Set Variable [$result; Value:MBS("CURL.SetOptionCookie"; $curl; "iPlanetDirectoryPro=AQI....A3*")]

              Set Variable [$result; Value:MBS("CURL.SetOptionPost"; $curl; 1)]

              //  Set Variable [$result; Value:MBS("CURL.OpenInputFile"; $curl; "/path/to/data.json")]

              Set Variable [$result; Value:MBS("CURL.SetOptionPostFields"; $curl; "{your json here}")]

              #RUN now

              Set Field [CURL Test::Result; MBS("CURL.Perform"; $curl)]

              #Check result

              Set Field [CURL Test::Text; MBS("CURL.GetResultAsText"; $curl; "UTF8")]

              Set Field [CURL Test::debug; MBS("CURL.GetDebugAsText"; $curl)]

              #Cleanup

              Set Variable [$result; Value:MBS("CURL.Cleanup"; $curl)]

              • 4. Re: Best Way to POST with a COOKIE
                deninger

                I am doing exactly what you did and am getting a different result than what I get when manually curling this.

                 

                The CURL.getDebugAsText give me:

                 

                  Trying...

                Connected to zzz.bbc.ccc.com (xxx.yyy.zzz.204) port 443 (#0)

                ALPN, offering http/1.1

                Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH

                TLSv1.2 (OUT), TLS header, Certificate Status (22):

                TLSv1.2 (OUT), TLS handshake, Client hello (1):

                TLSv1.2 (IN), TLS handshake, Server hello (2):

                TLSv1.2 (IN), TLS handshake, Certificate (11):

                TLSv1.2 (IN), TLS handshake, Server key exchange (12):

                TLSv1.2 (IN), TLS handshake, Server finished (14):

                TLSv1.2 (OUT), TLS handshake, Client key exchange (16):

                TLSv1.2 (OUT), TLS change cipher, Client hello (1):

                TLSv1.2 (OUT), TLS handshake, Finished (20):

                TLSv1.2 (IN), TLS change cipher, Client hello (1):

                TLSv1.2 (IN), TLS handshake, Finished (20):

                SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384

                ALPN, server did not agree to a protocol

                Server certificate:

                  subject: C=US; ST=xxx; L=yyy; O=zzz Corp; OU=aaa WOS of; CN=c zzz.bbc.ccc.com

                  start date: May  5 00:00:00 2016 GMT

                  expire date: Jun  1 23:59:59 2017 GMT

                  issuer: C=US; O=Symantec Corporation; OU=Symantec Trust Network; CN=Symantec Class 3 Secure Server CA - G4

                  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.

                POST /qa/cpscert/apienrollment/rest/v1/json/message/enrollment HTTP/1.1

                Host:  zzz.bbc.ccc.com

                Accept: */*

                Cookie: iPlanetDirectoryPro=AQI...c.*

                Content-Type: applicationjson

                Content-Length: 578

                 

                 

                upload completely sent off: 578 out of 578 bytes

                HTTP/1.1 400 Bad Request

                Server: Server

                Date: Mon, 29 Aug 2016 15:24:33 GMT

                X-frame-options: SAMEORIGIN

                X-content-type-options: nosniff

                X-xss-protection: 1; mode=block

                Location:

                Content-type: text/html;charset=utf-8

                Content-language: en

                Content-length: 1033

                Vary: Accept-Encoding

                Via: 1.1 https-ms.archer.qa_21020

                Proxy-agent: Oracle-iPlanet-Web-Server/7.0

                 

                 

                Connection #0 to host  zzz.bbc.ccc.com left intact

                 

                When sending this by curl from the command line I get back JSON and a result response...