HTTP 406 Error When Using Angular $http.get Against SharePoint REST End Points

புதுப்பி: Marc AD ndersson pointed out this great piece of info: HTTP://blogs.office.com/2014/08/13/json-light-support-rest-sharepoint-api-released/. That explains a lot :).

That may be the worst title of a blog post ever! Anyhoo.

I typically do all of my prototyping against an O365 instance. I have my personal instance so that I don’t have to be worried about affecting anyone else. As an aside – remember when we call carried around virtual machines on our laptops with MOSS – SQL Server, IIS, deciding Hyper-V vs. VMWare? Anyhoo…

I had developed an app using Angular in this environment that does, மற்ற விஷயங்களை, இந்த:

$http.get(serverUrl)
.success(செயல்பாடு(தரவு, அந்தஸ்து, headers, கட்டமைப்பு) {

var getLinksResponse = data;

getLinksResponse.value.forEach(செயல்பாடு(theResult) {

// and so on and so froth

This was working just fine in two different SharePoint online environments. எனினும், when my colleague ported it to a Cloudshare instance, he was getting an HTTP 406 பிழை (which was the first time I ever got that one, so … yay, I guess). We did a bit of research and noticed that the “Accept” header was off. SharePoint online was perfectly happy with:

Accept: application/json

But the cloudshare instance (which is SP on prem, hosted in a virtual server) wanted the classic “odata=verbose” added in as well:

Accept: application/json;odata=verbose

To fix that, we added the header as such:

var config = {headers: {
‘Accept’: ‘application/json;odata=verbose’
}
};

$http.get(serverUrl,கட்டமைப்பு)
.success(செயல்பாடு(தரவு, அந்தஸ்து, headers, கட்டமைப்பு) {

var getLinksResponse = data;

getLinksResponse.value.forEach(செயல்பாடு(theResult) {

// and so on and so froth

That got rid of the 406, but it also changed the format of the response. It was more … verbose. (haha!) More changes were required and here’s the final result:

var config = {headers: {
‘Accept’: ‘application/json;odata=verbose’
}
};

$http.get(serverUrl,கட்டமைப்பு)
.success(செயல்பாடு(தரவு, அந்தஸ்து, headers, கட்டமைப்பு) {

var getLinksResponse = data;

getLinksResponse.d.results.forEach(செயல்பாடு(theResult) {

// and so on and so froth

This only turned into a 30 minute problem for us, so we lucked out. Hopefully someone finds this useful.

</இறுதியில்>

2 "மீது எண்ணங்கள்HTTP 406 Error When Using Angular $http.get Against SharePoint REST End Points

  1. மார்க் டி ஆண்டர்சன்

    பால்:

    I think you were caught by the JSON lite option explained in this post on the Office Blogs:
    http://blogs.office.com/2014/08/13/json-light-support-rest-sharepoint-api-released/
    Since that change, if you don’t specify a value, it defaults to minimalmetadata. I don’t think this has made it to on premises installs yet, thus the disconnect.

    எம்.

ஒரு பதில் விட்டு பால் கால்வின் பதிலை நிருத்து

உங்கள் மின்னஞ்சல் முகவரி வெளியிடப்பட்ட முடியாது. தேவையான புலங்கள் குறிக்கப்பட்டன *