02-27-2020 08:57 AM
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.
02-28-2020 11:18 AM
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
02-28-2020 11:18 AM
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
03-02-2020 10:19 AM
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?
03-02-2020 11:26 AM
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.
03-02-2020 12:42 PM
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?
03-02-2020 01:29 PM
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
03-03-2020 07:58 AM
Ok.. Thank you very much..
Explore our Alfresco products with the links below. Use labels to filter content by product module.