【问题标题】:Calling Share point REST API from Angular Application从 Angular 应用程序调用共享点 REST API
【发布时间】:2020-02-16 03:45:16
【问题描述】:

场景:

在 Angular 应用程序中,我们使用 HTTP.get() 来访问 SHARE POINT REST api url。 分享点网址为公共网址,任何人均可访问。 结果:我们收到 401 未经授权的错误。

如果我们在网络浏览器中点击相同的 url,我们就能毫无问题地获得响应。

观察:

当我们在普通网络浏览器中点击 rest api 时,我们将 TYPE 设置为“文档”。 当我们在 Angular 应用程序中使用其余 api 时。请求的类型为“XHR”。 请任何人帮助我们解决这个问题。

【问题讨论】:

  • 可以分享代码吗?
  • 可能是您没有在请求中包含用户凭据,这可能会导致通常使用 SharePoint 设置的 Windows 身份验证出现问题 - 也许尝试包括 new RequestOptions({ withCredentials: true });
  • @Niladri,这就是我在代码中使用的方式。 ` return this.http.get('uaturl:8080/sites/getUser/_api/web/currentUser') .pipe(map((response: any) => { console.log(response); }), catchError((e) => { //console.log( ); })); `
  • @kishoreaoe 您需要在标头中发送共享点的凭据或使用withCredentials
  • @Niladri,你是救世主。!!添加后我可以得到它..非常感谢.!

标签: angular


【解决方案1】:

您是否尝试将 odata=verbose 添加到您的标题中?

{
            "accept": "application/json;odata=verbose",
            "content-Type": "application/json;odata=verbose"
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多