【发布时间】:2016-05-17 13:27:48
【问题描述】:
我需要以以下 JSON 格式发布 REST 调用。请注意,有效负载变量是 XML。我正在使用带有 CURL 的 PHP 5。寻找我做错了什么。谢谢
{
"processDefId":"testing~SimpleApplication!1.0~SimpleProcess",
"serviceName":"SimpleProcess.service",
"operation":"start",
"payload":"<payload><formArg><p0:WebForm1 xmlns:p0=\"http://www.frevvo.com/schemas/_N5J6IBUOEeWgf4K8GSSanA\"/></formArg></payload>",
"action":"Submit"
}
构建了以下内容,但没有得到响应,也没有看到任何对被调用应用程序的操作。
try {
echo '<br>Curl Start<br>';
echo file_put_contents($log, "Start \n", FILE_APPEND);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"http://192.168.56.151:7003/bpm/api/3.0/processes");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_FAILONERROR);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json') );
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json') );
curl_setopt($curl, CURLOPT_USERPWD, "jstein:welcome1");
$xml = '<ns1:start xmlns:ns1=\http://xmlns.oracle.com/bpm/webform/formsData/requestTravelAccount\">';
$xml .= '<formArg xmlns:ns2=\"http://www.frevvo.com/schemas/_1g73gMt3EeWsKsy3N_19_Q\">';
$xml .= '<ns2:RequestTravelAccount>';
$xml .= '<EmployeeId>1771</EmployeeId>';
$xml .= '<FirstName>Aaron</FirstName>';
$xml .= '<LastName>Thompson</LastName>';
$xml .= '<PersonId>300000087953021</PersonId>';
$xml .= '</ns2:RequestTravelAccount>';
$xml .= '</formArg>';
$xml .= '</ns1:start>';
$xml_e = htmlspecialchars($xml, ENT_QUOTES);
echo file_put_contents($log, $xml_e ."\n", FILE_APPEND);
$post_data = array(
"processDefId"=>"testing~HCM!1.0~NewEmployeeTravelSetupProcess",
"serviceName"=>"NewEmployeeTravelSetupProcess.service",
"operation"=>"start",
"action"=>"Submit",
"payload" => $xml_e
);
$curl_post_data = json_encode($post_data);
echo file_put_contents($log, "$curl_post_data"."\n", FILE_APPEND);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_response = curl_exec($curl);
echo '<br> CURL_EXEC return: ' . curl_error($curl);
} catch (Exception $e) {
echo 'Caught exception" ',$e->getMessage(), "\n";
}
curl_close($curl);
echo '<br>CURL done';
【问题讨论】: