0
我在我的REST API(使用SLIM框架)中创建了一个测试函数,用于测试云转换API的包装类的实现。在我的REST API中调用cloudconvert API
$app->get('/test', 'authenticate', function() use ($app) {
$response = array();
$converter = new CloudConverter();
$url = $converter->createProcess("docx","pdf");
$response["url"] = $url;
echoRespnse(201, $response);
});
CloudConverter类里面我CreateProcess函数看起来像这样:
public function createProcess($input_format,$output_format)
{
$this->log->LogInfo("CreateProcess Called");
$headers = array('Content-type: application/json');
$curl_post_data = array('apikey' => API_KEY,'inputformat' => $input_format,'outputformat' => $output_format);
$curl = curl_init(CLOUD_CONVERT_HTTP);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));
$curl_response = curl_exec($curl);
if ($curl_response === false)
{
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
$this->log->LogInfo('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response,true);
return $decoded['url'];
}
我已经使用Chrome高级REST客户端测试了我的API,我看到我的电话给cloudconvert API的成功响应,但这不是我期待的,正如在上面的代码中可以看到的那样。我期待提取网址并在我的回复中返回THAT。
我的问题是: 我怎样才能从cloudconvert响应提取URL并返回,在我自己的反应。
非常感谢。我只是通过curl_setopt选项阅读,但你击败了我:)再次感谢.. .. – DTH