Greetings:
I'm trying to use the web proxy feature in SP 2013. Here is the code:
var hostWebUrl = "http://contoso.com/somepage.html"; var request; var response; function successHandler() { if (response.get_statusCode() == 200) { //everything is good $("#DivTagId").html(response.get_body()); } else { var msg = "Response returned: " + response.get_statusCode(); msg += "<br/>" + response.get_body(); $("#DivTagId").html(msg); } } function errorHandler() { var msg = "Error!<br/>" + response.get_body(); $("#DivTagId").html(msg); } function loadData () { try { var context = SP.ClientContext.get_current(); request = new SP.WebRequestInfo(); request.set_url(hostWebUrl); request.set_method("GET"); request.set_headers({"Accept":"text/html"}); response = SP.WebProxy.invoke(context, request); context.executeQueryAsync(successHandler, errorHandler); } catch (e) { console.log(e); } } SP.SOD.executeFunc("sp.js","SP.ClientContext",loadData);
The code executes and returns with a status code of 403 and a request body that says: "Calls to WebProxy without an app context are not allowed." I've used SP.ClientContext.get_current (see above). What am I missing?
- BigCountrix