amosbatto wrote:What is the rest of your code?
You need to use http_build_query() when sending the variables.
Code: Select allpublic function startCase($processId,$firstTaskId,$dataTable,$dataId){
$user = $this->username;
$pwd = $this->passward;
//请求地址从配置获取并组装!!!!!!!
//$url = "http://localhost:8000/api/1.0/workflow/cases";
$url = self::PM_HOST.self::PM_RESTAPI_PATH.self::PM_WORK_SPACE."/cases";
//传入对应的业务数据
$variables = json_encode(array(
"dataTable" => $dataTable,
"dataId" => $dataId
));
$postParams = array(
'pro_uid' => $processId,
'tas_uid' => $firstTaskId,
'variables' => $variables
);
$oToken = $this->getPMAccessToken($user, $pwd);
$accessToken = $oToken->access_token;
$ret = $this->pmRestRequest("POST",$url,$postParams,$accessToken);
return $ret;
}
Code: Select all public function pmRestRequest($method = "GET",$url,$postParams = null,$accessToken){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$accessToken));
switch ($method){
case "GET" :
curl_setopt($ch, CURLOPT_HTTPGET, true);
break;
case "POST":
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($postParams));
break;
case "PUT" :
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($postParams));
break;
case "PATCH":
curl_setopt($ch, CULROPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
break;
case "DELETE":
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_POSTFIELDS,$postParams);
break;
}
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = json_decode(curl_exec($ch));
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$return = array(
"httpCode" => $statusCode,
"returnValue" => $ret
);
return $return;
}
I have used http_build_query(),but the response still raise error:400 Bad Request: Invalid value specified for `variables`