You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SharePoint REST API问题:含空格列表名无法通过getByTitle获取

解决SharePoint REST API带空格列表名称的调用问题

以下是适配动态工具需求的可行方案:

  • 替换空格为%20而非依赖URLEncoder.encode
    URLEncoder.encode会将空格转为+,但SharePoint REST API在getbytitle()的单引号参数内部仅识别%20作为空格的转义符。直接替换空格即可:
String listName = "TWO WORDS";
String encodedListName = listName.replace(" ", "%20");
String requestUrl = siteUrl + "/_api/web/lists/getbytitle('" + encodedListName + "')/items";
  • 扩展处理特殊字符
    如果列表名称包含&、#这类特殊字符,可针对性替换为对应URL编码,同时保留单引号包裹格式:
String listName = "TWO WORDS & TEST#1";
String encodedListName = listName.replace(" ", "%20")
                                .replace("&", "%26")
                                .replace("#", "%23");
String requestUrl = siteUrl + "/_api/web/lists/getbytitle('" + encodedListName + "')/items";
  • 检查URL格式细节
    确保请求URL满足以下要求:
    • 使用英文单引号包裹列表名称,不要用中文单引号
    • 拼接URL时没有引入多余转义或空格
    • 站点URL末尾无多余斜杠,避免拼接后出现//格式错误

内容的提问来源于stack exchange,提问作者Jeries Haddad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 11:45:30