Hi,
I have a issue when i consume the Alfresco APIs.
I have installing Alfresco Version 5.2.0 (201707).
I want consume the Alfresco APIs with PHP. I have a code in php i use JQUERY for that. I have used JQUERY, AJAX, AXION but but none works. In console i have this issue. "Access to XMLHttpRequest at 'http://localhost:8080/alfresco/service/api/login.json?u=admin&pw=admin' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."
I don't know if there is an SDK for PHP. I have used some SDK for PHP but is very OLD. Also i have added the permissions in the head and it doesn't work for me either.
This is my code. Is very simple!
<?php
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');
}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
} ?>
<html>
<head>
<script type = "text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
var surl = "http://localhost:8080/alfresco/service/api/login.json?u=admin&pw=admin";
$.ajax({
url: surl,
dataType: "json",
success: function (data) {
alert(JSON.stringify(data));
}
});
});
</script>
</head>
<body>
</body>
</html>
I hope someone can help me. Thank you.
Solved! Go to Solution.
Follow this document and configure cors on your installation: https://docs.alfresco.com/5.2/tasks/enable-cors.html
You can also look at this post, its not with PHP though but may give some hints: https://hub.alfresco.com/t5/application-development/adf-cors-solving-strategies/bc-p/286963
Some additonal posts related to CORS:
http://anshu-alfresco-one.blogspot.com/2015/08/enable-cors-in-alfresco-and-how-to-use.html
https://hub.alfresco.com/t5/application-development/enabling-cors/td-p/218640
Follow this document and configure cors on your installation: https://docs.alfresco.com/5.2/tasks/enable-cors.html
You can also look at this post, its not with PHP though but may give some hints: https://hub.alfresco.com/t5/application-development/adf-cors-solving-strategies/bc-p/286963
Some additonal posts related to CORS:
http://anshu-alfresco-one.blogspot.com/2015/08/enable-cors-in-alfresco-and-how-to-use.html
https://hub.alfresco.com/t5/application-development/enabling-cors/td-p/218640
Hi abhinavmishra
I was very helpful. I am very grateful. By last. Are there any codes made with PHP that I can try with these APIs?
Take a look at this post:
https://hub.alfresco.com/t5/alfresco-content-services-hub/php-api-tutorials/ba-p/289770
https://github.com/Alfresco/alfresco-php-sdk/tree/master/php-lib/source/php/api/Tutorials
https://github.com/alfresco/alfresco-php-sdk
Its an old post but might give you some ideas.
Thank you.
I see that many links do not work. And I have urged to install that SDK but the instructions link does not work. Do you have these links on another site working?
Unfortunately i don't have any other info. You can take the reference from the tutorial. Or try contacting the project owner on github. Its very old project though
Ok.. Thank you very much..
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.