It seems that the new REST API isn't able to receive POST requests encoded as multipart/form-data. As this is the default when passing an array of fields to cURL in PHP, it would be helpful if this could be supported.

As a workaround, applications can set the Content-Type header to 'application/x-www-form-urlencoded' and use http_build_query on the array to turn it into a URL-encoded string.


Comments

Hi,

This issue was resolved: multipart forms should now work.
No need to wait for a version-release or anything - should be working already.

Please let us know if you encounter any more problems with multipart forms.

Meir

Great, thank you. It seems to be working.

Note that you can make POST requests to Calais using cURL without setting the Content-Type header and without using http_build_query, which is only supported in PHP 5.

The following code relies on cURL's default when it receives a string as the POST data and can work with older versions of PHP:

/*
* Construct the POST data string
*/
$data = "licenseID=".urlencode("12345");
$data .= "&paramsXML=".urlencode(" ... ");
$data .= "&content=".urlencode($content);

/*
* Invoke the Web service via HTTP POST
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.opencalais.com/enlighten/calais.asmx/Enlighten");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);
$response = curl_exec($ch);

Thanks,
Shai Dagan

That's not really a solution, just a long-winded way of not using http_build_query.

The bug is that the web service should support data POSTed as multipart/form-data.