I am trying to create a sharepoint hosted app. That app is hosted on a sharepoint online site.
It is supposed to access data from a sharepoint online list that is on another site collection (but in the same office365 domain).
Everything is working over http.
I found an example on msdn that gets data from odata.org. When I use this code it works very well :
var context = SP.ClientContext.get_current();
var request = new SP.WebRequestInfo();
request.set_url(
"http://services.odata.org/Northwind/Northwind.svc/Categories"
);
request.set_method("GET");
// We need the response formatted as JSON.
request.set_headers({ "Accept": "application/json;odata=verbose" });
var response = SP.WebProxy.invoke(context, request);
// Let users know that there is some
// processing going on.
document.getElementById("categories").innerHTML =
"<P>Loading categories...</P>";
// Set the event handlers and invoke the request.
context.executeQueryAsync(successHandler, errorHandler);
function successHandler() {
// Check for status code == 200
// Some other status codes, such as 302 redirect
// do not trigger the errorHandler.
if (response.get_statusCode() == 200) {
var categories;
var output;
// Load the OData source from the response.
categories = JSON.parse(response.get_body());
// Extract the CategoryName and Description
// from each result in the response.
// Build the output as a list.
output = "<UL>";
for (var i = 0; i < categories.d.results.length; i++) {
var categoryName;
var description;
categoryName = categories.d.results[i].CategoryName;
description = categories.d.results[i].Description;
output += "<LI>" + categoryName + ": " +
description + "</LI>";
}
output += "</UL>";
document.getElementById("categories").innerHTML = output;
}
else {
var errordesc;
errordesc = "<P>Status code: " +
response.get_statusCode() + "<br/>";
errordesc += response.get_body();
document.getElementById("categories").innerHTML = errordesc;
}
}
// Event handler for the error event.
// Render the response body in the placeholder.
// The body includes the error message.
function errorHandler() {
document.getElementById("categories").innerHTML =
response.get_body();
}
However, if I change the Northwind url and use the url of my site lists (.../_api/web/lists), which is on https, I get a 403 Forbidden error. (I use this url only for testing purposes).
I think it may be a problem with https. I have read blog posts that advice to deactivate https on the sharepoint development server but it is not possible here since it is on sharpoint online. And I want to use https.
I have added the remote endpoint in the appmanifest of course.
Thank you