我正在尝试使用PHP和cURL执行DELETE http请求.
我已经阅读过如何在很多地方做到这一点,但似乎没有什么对我有用.
我是这样做的:
public function curl_req($path,$json,$req)
{
$ch = curl_init($this->__url.$path);
$data = json_encode($json);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $req);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data)));
$result = curl_exec($ch);
$result = json_decode($result);
return $result;
}
Run Code Online (Sandbox Code Playgroud)
然后我继续使用我的功能:
public function deleteUser($extid)
{
$path = "/rest/user/".$extid."/;token=".$this->__token;
$result = $this->curl_req($path,"","DELETE");
return $result;
}
Run Code Online (Sandbox Code Playgroud)
这给了我HTTP内部服务器ERROR.在我的其他函数中使用与GET和POST相同的curl_req方法,一切顺利.
那么我做错了什么?