SharePoint 2013: POST Requests to Search Service through App

SharePoint 2013: POST Requests to Search Service through App

We recently experienced an issue when developing a SharePoint hosted App on SharePoint 2013.

The App should query the SharePoint Server Search Service based on all sites a user is following and should display some data according to this criteria. The result of the “Following” site URL’s can be too long for a “GET” request so an implementation with a “POST” request would need to do it.

After implementing the App, opened from the catalog, would work as expected. But if the App is placed in a webpartzone as App-Part, the error „No transport“ was displayed. Thats about all we get as error description.

What did the trick in the end was to seperately aquire a FormDigest.

Executing a POST request using REST, the FormDigest of the page being posted to is required (security validation). Since a SharePoint App part is hosted in an iframe, it is not possible to retrieve the FormDigest of the host web using $(“#__REQUESTDIGEST”).val().

        $.ajax({

url: SPAppWebUrl + „/_api/contextinfo‘,

type: ‚POST‘,

contentType: ‚application/json;odata=verbose‘,

headers: { ‚Accept‘: ‚application/json;odata=verbose‘ },

success: function (data) {

formDigest = data.d.GetContextWebInformation.FormDigestValue;

},

error: ajaxFail,

async: false

});

 

return formDigestValue;

Leave a Reply

  

  

  

Time limit is exhausted. Please reload CAPTCHA.