3

I am authenticating with cookie to online Sharepoint, as answered here:

REST - Authentication to online Sharepoint

When I try to authenticate I get 401 error.

This is my code:

   List<String> fileList = new ArrayList<>();
try {
    //here I get cookie value
    CookieStore cookieStore = getCookieStore(.....);
    HttpClient httpClient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
    String uri = URL  + "/" + "_api/web/GetFolderByServerRelativeUrl(\'" + FOLDER_NAME + "\')/files";        
    HttpGet httpGet = new HttpGet(uri);
    httpGet.addHeader("Accept", "application/json;odata=verbose");
    httpGet.addHeader("X-FORMS_BASED_AUTH_ACCEPTED", "f");

    // Make the request.
    HttpResponse response = httpClient.execute(httpGet);
    // Process the result
    int statusCode = response.getStatusLine().getStatusCode();
    if (statusCode == 200) {
       ......
    }
} catch (Exception e) {
    log.error("", e);
}

My cookie store is something like this: [[version: 0][name: SPOIDCRL][value: 77u/PD94bWwgdmVyc2lvbj.......

But, I am geting 401 with error: HTTP/1.1 401 Unauthorized

Again I can't authorise to SP. Can you help me one more time?

Thanks

1

I have not tried the Java client. But I can successfully issue the same request with the HttpClient class in the .NET framework. Make sure the cookie has the format:

SPOIDCRL=77u/PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48...

Also, you do not need to include the X-FORMS_BASED_AUTH_ACCEPTED header.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.