我已经在PHP中构建了一个表单,该表单通过AJAX提交给脚本,该脚本需要发布到Workfront API以便在通用的万能项目中创建新任务。
当我在浏览器(Chrome)地址栏中输入以下URL +查询时,它确实成功创建了任务,因此现在我需要对其进行调整以在PHP中工作:
https://MY-DEPT-NAME.preview.workfront.com/attask/api/v9.0/task/?name=New%20Task&description=This%20is%20my%20wonderful%20shiney%20new%20task&method=POST&apiKey=8ffskq9hj3q0swnzi6z1ixf9tl8qbop8&projectID=5b6358d7002b1b5c69342a098d752158
这是我拥有的代码,部分基于GitHub中的Workfront示例代码。您能看到我想念的或做错的吗? (名称和描述将替换为表单中的输入。)
$url = "https://MY-DEPT-NAME.preview.workfront.com/attask/api/v9.0/task/";
$data = array(
'name' => 'My New Task',
'description' => 'This is my wonderful shiney new task',
'method' => 'POST',
'apiKey' => '8ffskq9hj3q0swnzi6z1ixf9tl8qbop8',
'projectID' => '5b6358d7002b1b5c69342a098d752158'
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
if ($data){
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
var_dump( $result );
curl_close( $curl );
var_dump( $curl );
我目前从这些var_dump中得到的结果是: “类型(未知)的布尔(假)资源(1)”