FMDiff™   

FileMaker Business Alliance
View Jürgen Geßwein's profile on LinkedIn

This site is W3C compliant:
Valid XHTML - Valid CSS
Last modified February 24 2016, 20:37:20 CET.

HTTP POST from FileMaker

Go to Reader Comments at the bottom of the page

How to show the results of a POST command in WebViewer

Use cURL to send a POST and show the result in WebViewer

As of version 8.5, FileMaker® Pro is not able to send POST commands to a web server from scratch and show the results in a WebViewer frame (without first loading a web page that contains a HTML FORM and a submit button). You can mimic a POST command and show the result page in WebViewer with the aid of cURL and either AppleScript, Shell Plug-in, or VB-Script.

Don't mix up POST and GET commands. While with a GET you simply append the arguments to the URL, like "http://www.shipper.com/search.asp?arg1=12345&arg2=xyz", POST uses the arguments of a HTML FORM that may contain any kind of data, like input fields, text areas, hidden fields, button names, position of clicked graphics, and cookie data.

The following example uses the Shell plug-in on Mac OS X. We assume a freight carrier URL and a shipment ID have to be posted to receive a result page. We save the HTML to disk and then show this file in the WebViewer.

The Setup

cURL should already be available with Mac OS X.

The Shell plug-in - as of this writing - can be freely downloaded from abstrakt.com. It works with FileMaker versions 6 to 9, but not on Intel Macs.

There are newer plug-ins available that require FileMaker Pro 7 and up, like zippShell (PPC and Intel) by John Kornhaus and ScriptMaster (all platforms) by 360works.com.

In your FileMaker file (named here PostAndWebViewer) you need some fields, a script, a layout with a WebViewer object, and possibly a button that triggers the script. The fields are:

theURL    // the path to the web server
          //    "http://www.shipper.com/search.asp"
theArg    // the argument label                        "shipmentID"
theID     // (number) the individual query ID
gHtml     // a global field for the raw HTML data received
localFile // the common name for local storage         "shipper"
uPath     // unstored calculation for the file path
          // Get ( DesktopPath ) & localFile & theID & ".php"

The script looks like this:

Commit Records/Requests [ No dialog ] 
Set Variable [ $query; Value: 
     "curl " & PostAndWebViewer::theURL & 
     " --data " & PostAndWebViewer::theArg & 
     "=" & PostAndWebViewer::theID ] 
Set Field [ PostAndWebViewer::gHtml;
                   External ( "shell-Execute"; $query ) ] 
Set Variable [ $file; 
     Value:PostAndWebViewer::localFile &
     PostAndWebViewer::theID & ".php" ] 
Export Field Contents [ PostAndWebViewer::gHtml; “file:$file” ] 
View As [ View as Form ] 

Commit Records/Requests makes sure that a newly entered or dragged ID is used.

To set up the variable $query beforehand makes the External call much clearer. Check out the cURL manual for all other possibilities.

The field gHtml receives the web page.

localFile is set up in $file and then exported as "shipper1234567" to the desktop. We need that variable $file here, since only variables can be passed as file path parameter. You may change the uPath calculation to point to any convenient location. Make sure you have write access there.

The most strange and remarkable script step above is View As. In my tests it turned out, that this was the only reliable command that forced the WebViewer to reload the newly saved file.

To work with cookies (receive and submit) define a variable $cookie with an arbitrary path to a file and add

" -b " & $cookie & " -c " & $cookie

to your cURL query. Some servers also insist on a HTTP_USER_AGENT. This can be provided by adding

" -A Mozilla/5.0"

or similar to the query. Suggestion: read the cURL manual and experiment.

You may also use a secure login with HTTPS:

" -u " & $login    // $login="username:password"

The WebViewer object is defined to show this custom URL:

"file:/" & PostAndWebViewer::uPath

If you want to avoid many local files, store the HTML in a record. The draw-back is clear: the contents has to be exported every time the record is shown. On the other hand the information may have been updated on the server while you are still looking at your old file. It depends on your needs what way you choose.

This is just the beginning. With cURL you can do a lot of things that otherwise are not possible.

 

A Cheaper Alternative

You can assemble a HTML document with a calculation that just contains a FORM element with all necessary data in hidden fields and a submit button. Export that field content to the disk and show it in the WebViewer. Clicking on Submit would send the form to the server and show the result in the WebViewer.

Indenting and spaces are added just for better readability. The whole document may be squeezed into one line.

<html>
<body>
   <p> Notify me when a new version of FMDiff becomes available </p>
   <form action="http://fmdiff.com/notifyme.php" method="post" name="fo">
      <input type="hidden" name="fo[namef]"  value="first name" />
      <input type="hidden" name="fo[name]"   value="last name" />
      <input type="hidden" name="fo[email]"  value="" />
      <input type="submit" name="ifRequired" value="Notify me" />
      Press button to go to the web site
   </form>
</body>
</html>

Do it without using a file

Instead of saving the page to disk, you can feed that calculated HTML directly into the WebViewer. Define a Custom Web Address in WebViewer like that:

Case ( Get ( SystemPlatform ) = -2 ; "about:" ; "data:text/html," ) &
"<html>
<body>
   <p> Notify me when a new version of FMDiff becomes available </p>
   <form action=\"http://fmdiff.com/notifyme.php\" method=\"post\" name=\"fo\">
      <input type=\"hidden\" name=\"fo[namef]\"  value=\"first name\" />
      <input type=\"hidden\" name=\"fo[name]\"   value=\"last name\" />
      <input type=\"hidden\" name=\"fo[email]\"  value=\"\" />
      <input type=\"submit\" name=\"ifRequired\" value=\"Notify me\" />
      Press button to go to the web site
   </form>
</body>
</html>"

This renders like that:

Notify me when a new version of FMDiff becomes available

Press button to go to this web site

Note: You have to provide every information a server requires. Some servers are easily satisfied, others (like ours) are very picky about what to accept. What the server expects you'll find in the web page's form element you normally use with a browser. Sometimes a JavaScript provides or obfuscates some data.

You may download a full functioning sample file utilizing the simplest possible solution (just a WebViewer calculation) WebViewerTest.fp7.zip (7 kByte) for exploration. (Does not work on Windows, see note below.)

Note: Unfortunately the "about:" URL does not work for Internet Explorer (which is the base for WebViewer on Windows) anymore since Windows 2000 SP2 and later systems, for security reasons. Experts may be able to add their own fixed page to the system like res://myIElibrary.dll/myPage.htm, add the appropriate Registry entry, and would then be able to open it with about:myPage.

So the easy way to go on Windows is to save the file to disk and read it from there. This requires no extra installation but a directory with write permission.

For more demanding applications I recommend installing cURL because it's a lot more flexible (see top of page).

Have fun!

 

Reader Comments

Thanks Winfried for your example,
  Some more great news! Installing the shell plugin on FileMaker server web publishing allows it to work with server instant and custom web publishing! I installed it here:

C:\Program Files\FileMaker\FileMaker Server\Web Publishing\publishing-engine\wpc\Plugins  

and I had to also install curl on the server computer. I also had to restart the web publishing services from the services window and now I can do curl commands from FileMaker Server instant and custom web publishing! Awesome! Thanks!


Examples are provided "AS IS" without warranties of any kind. Use at your own risk.

© 2005 - 2015 Winfried Huslik †. © 2024 Jürgen Geßwein. All Rights Reserved. FMDiff and FMVis are trademarks of Jürgen Geßwein, Augsburg, Germany. FileMaker is a trademark of FileMaker Inc., Santa Clara, CA, USA. Other trademarks mentioned are property of their respective owners. This web site has not been authorised, sponsored, or otherwise approved by FileMaker, Inc.