【发布时间】:2019-07-08 15:13:40
【问题描述】:
我正在尝试使用过滤器参数发出 REST API 请求。我的网址在浏览器中工作正常,但在 JS 请求号中。
https://xxxx.sharepoint.com/sites/myTestPage/_api/web/lists/getbytitle('ListDemo')/Items?$top=200&$select=State
任何参数条件都有效,谁能帮帮我。
下面是我用来测试和制作JS文件相同步骤的powershell脚本:
$url = "https://xxxx.sharepoint.com/sites/myTestPage/_api/web/lists/getbytitle('ListDemo')/Items?$top=200&$select=State"
$headers = @{}
$headers.Add("Authorization","Bearer " + $bearerCode)
$headers.Add("accept","application/json; odata=minimalmetadata")
#$headers.Add("content-type","application/json;odata=verbose")
$headers.Add("content-type","application/json;odata=minimalmetadata")
$headers.Add("Control-Allow-Origin","https://xxxx.sharepoint.com")
$headers.Add("Origin","https://xxxx.sharepoint.com")
$response = Invoke-WebRequest -Uri $url -Method GET -Header $headers
Write-host $response.RawContent
【问题讨论】:
-
网址中没有过滤器,问题出在哪里?您只需加载多达 200 个项目,并且只有一个字段 - 状态。这个脚本对你有用吗?不用设置 content-type、control-allow-origin 或 origin,没用。授权和接受就好了。
-
是的,我知道。我有一个简单的网址,每个人都知道任何事情都对我有用。我曾尝试链接为 $filter=City eq 'DC'&$select=City,Campaign_x0020_Type,ContentType,Country,Audience_x0020__x002d__x0020_EX_,但它也不起作用。关于来源和内容类型,它是必需的,因为我正在进行外部访问。它不是 SharePoint 插件。
-
我看不出过滤器参数有什么问题。那么在浏览器和 PowerShell 中,url 可以正常工作并加载正确的数据吗?您提到它在 JS 中不起作用,您能分享一下您是如何调用它的吗?
标签: rest sharepoint office365 sharepoint-online