User offline. Last seen 1 year 33 weeks ago. Offline
Joined: 06/11/2008

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.

Trackback URL for this post:

http://www.opencalais.com/trackback/7092

Login or Register to post a comment.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
User offline. Last seen 1 year 6 weeks ago. Offline
Joined: 12/20/2010

thanks for good article.!

User offline. Last seen 1 year 8 weeks ago. Offline
Joined: 12/11/2010

thanks .. now the problem does not seem http_build_query

User offline. Last seen 2 years 18 weeks ago. Offline
Joined: 06/01/2008

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

User offline. Last seen 1 year 33 weeks ago. Offline
Joined: 06/11/2008

Great, thank you. It seems to be working.

User offline. Last seen 2 years 36 weeks ago. Offline
Joined: 12/31/1969

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

User offline. Last seen 1 year 33 weeks ago. Offline
Joined: 06/11/2008

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.