0

I need to delete opencast matterhorn recording via REST api which they already provided. (just for the information, no need to worry about matterhorn)

I need to develop simple PHP code to DELETE some entries via given REST API. I have tested with curl command line it is working fine, but I can't convert that into working PHP code.

working curl command :

curl --digest -X "DELETE" -u matterhorn_system_account:CHANGE_ME -H "X-Requested-Auth: Digest" -H "X-Opencast-Matterhorn-Authorization: true" url/search/xxxx

not working PHP command :

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'url/search/xxxx');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, 'matterhorn_system_account:CHANGE_ME');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Requested-Auth: Digest"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Opencast-Matterhorn-Authorization: true"));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

result $httpCode is 302, means it's not working.

Any idea where I went wrong.

Thanks in advance

1 Answer 1

1

You need to combine these two so you aren't overwriting yourself:

curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Requested-Auth: Digest"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Opencast-Matterhorn-Authorization: true"));

So that should be

curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Requested-Auth: Digest", 
                                           "X-Opencast-Matterhorn-Authorization: true"));

And it probably would also help to follow redirects with

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
Sign up to request clarification or add additional context in comments.

1 Comment

you save my day, its works for me. with and without CURLOPT_FOLLOWLOCATION, it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.