我正在使用SharePoint 2013 onprem和在线版本进行集成。在访问用于在线SharePoint的REST API时,我能够使用application/json
和application/xml
作为ACCEPT
标头,没有任何问题。
但是,在访问SharePoint 2013 onpremise REST API时,我可以使用application/xml
作为ACCEPT
标头并使用application/json
抛出以下错误:
GET - http://xxxxxxx:8300/_api/web/
Header -
Accept:application/json
Response:
{
"error": {
"code": "-1, Microsoft.SharePoint.Client.ClientServiceException",
"message": {
"lang": "en-US",
"value": "The HTTP header ACCEPT is missing or its value is invalid."
}
}
}
您能否建议我如何获取LIST,LISTITEM对象的JSON响应?
答案 0 :(得分:1)
试试这个:
"accept": "application/json; odata=verbose"
答案 1 :(得分:1)
我在内部部署SharePoint 2013之前遇到过这种类型的问题。迈克的答案也有其优点。您需要将Accept标头值更改为“ application / json; odata = verbose ”,但我不认为这是问题所在。我认为您需要修补SharePoint的内部部署实例以支持OData 3和JSON Light。请仔细阅读以下blog post中的说明。当我们在现场部署解决方案时,当我们从REST API请求json时,我们仍然会发现遇到此问题的服务器场。但是,您更有可能在刚刚开发的开发实例中找到它。解决起来相对快速和简单。祝你好运!
<强> 编辑: 强>
最近删除了Technet文章。这是WCF Data Services 5.6的下载链接。仍然遵循原始帖子中的指导,我认为你会快速启动并运行。此外,您应该能够在此次更新后删除Accept标头的 odata = verbose 部分。
PowerShell完成升级(在WCF数据服务安装后运行) 在升级的WCF数据服务所在的SharePoint Server上运行此命令。
$configOwnerName = "JSONLightDependentAssembly"
$spWebConfigModClass ="Microsoft.SharePoint.Administration.SPWebConfigModification"
$dependentAssemblyPath ="configuration/runtime/*[local-name()='assemblyBinding' and namespace-uri()='urn:schemas-microsoft-com:asm.v1']"
$dependentAssemblyNameStart ="*[local-name()='dependentAssembly'][*/@name='"
$dependentAssemblyNameEnd = "'][*/@publicKeyToken='31bf3856ad364e35'][*/@culture='neutral']"
$dependentAssemblyValueStart = "<dependentAssembly><assemblyIdentity name='"
$dependentAssemblyValueEnd ="' publicKeyToken='31bf3856ad364e35' culture='neutral' /><bindingRedirect oldVersion='5.0.0.0' newVersion='5.6.0.0' /></dependentAssembly>"
$edmAssemblyName ="Microsoft.Data.Edm"
$odataAssemblyName ="Microsoft.Data.Odata"
$dataServicesAssemblyName ="Microsoft.Data.Services"
$dataServicesClientAssemblyName ="Microsoft.Data.Services.Client"
$spatialAssemblyName ="System.Spatial"
$assemblyNamesArray = $edmAssemblyName,$odataAssemblyName,$dataServicesAssemblyName,$dataServicesClientAssemblyName, $spatialAssemblyName
Add-PSSnapin Microsoft.SharePoint.Powershell
$webService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
################ Adds individual assemblies ####################
For ($i=0; $i -lt 5; $i++)
{
echo "Adding Assembly..."$assemblyNamesArray[$i]
$dependentAssembly = New-Object $spWebConfigModClass
$dependentAssembly.Path=$dependentAssemblyPath
$dependentAssembly.Sequence =0 # First item to be inserted
$dependentAssembly.Owner = $configOwnerName
$dependentAssembly.Name =$dependentAssemblyNameStart + $assemblyNamesArray[$i] + $dependentAssemblyNameEnd
$dependentAssembly.Type = 0 #Ensure Child Node
$dependentAssembly.Value = $dependentAssemblyValueStart + $assemblyNamesArray[$i] + $dependentAssemblyValueEnd
$webService.WebConfigModifications.Add($dependentAssembly)
}
###############################################################
echo "Saving Web Config Modification"
$webService.Update()
$webService.ApplyWebConfigModifications()
echo "Update Complete"
答案 2 :(得分:0)
更改此
标题:
{
“接受”:“application / json”,
},
试试这个 标题: { “接受”:“application / json; odata = verbose”, },