HTTP POST from FileMaker

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:

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.

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:

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.