2

Scenario:

From Angular application, we are using HTTP.get() in order to hit SHARE POINT rest api url. Share point URL is public url and can be accessed by any one. Result: We are getting 401 unauthorized error.

If we hit the same url in the web browser, we were able to get the response with out any problem.

Observations:

when we hit the rest api in normal web browser, we are getting TYPE as 'document'. when we hit the rest api with in Angular Application. the request is going as TYPE 'XHR'. Anyone please help us on this issue.

8
  • Can you share the code? Commented Oct 30, 2018 at 14:00
  • It may be that you're not including the users credentials with the request which could cause trouble for the windows authentication usually setup with SharePoint - maybe try including new RequestOptions({ withCredentials: true }); Commented Oct 30, 2018 at 14:02
  • @Niladri, This is how i am using in the code. ` return this.http.get('uaturl:8080/sites/getUser/_api/web/currentUser') .pipe(map((response: any) => { console.log(response); }), catchError((e) => { //console.log(); })); ` Commented Oct 30, 2018 at 14:09
  • @kishoreaoe you need to send the credential for sharepoint in header or using withCredentials Commented Oct 30, 2018 at 14:17
  • @Niladri, You are savior.!! After adding this i could able to get it.. thanks alot.! Commented Oct 30, 2018 at 14:53

1 Answer 1

0

Have you tried adding odata=verbose to your header?

{
            "accept": "application/json;odata=verbose",
            "content-Type": "application/json;odata=verbose"
}
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, We have tried by adding all the possible headers. Still it is giving 401 un-authorized while hitting the sharepoint rest url.
have a look to this article, hope it's helpful sharepoint.stackexchange.com/questions/52112/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.