0

我正在尝试调用 ConvertAPI.com/Word2Pdf,但没有成功。

我的示例代码是:

$fileToConvert = 'test.docx';
$apiKey = *******;
$postdata = array('OutputFileName' => 'test.pdf', 'ApiKey' => $apiKey, 'File' => $fileToConvert);
$ch = curl_init("http://do.convertapi.com/Word2Pdf");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$result = curl_exec($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
var_dump($result);

我得到的结果是:“HTTP/1.1 100 Continue HTTP/1.1 400 'File' 参数不能为空。请设置值。缓存控制:无缓存,无存储杂注:无缓存内容-类型:文本/html..."

我在这里做错了什么?

4

1 回答 1

0

尝试使用http://unirest.io/php.html

$response = Unirest::post(
  "http://do.convertapi.com/Word2Pdf?ApiKey=<Your api key>",
  array(
    "File" => "@/tmp/file.path",
    "OutputFormat" => "pdf",
  )
);
于 2014-05-13T21:27:44.357 回答