javantlmntlm-authentication

Java NTLM Athentication for sharepoint online services getting 401 error


i tried the below code for getting lists from a clients sharepoint service (2013) its an https (invalid certificcate),i have downlaoded the same certiite and instaleld in cacets.everytime im getting the below response

    try{
        HttpParams  params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        DefaultHttpClient httpClient = new DefaultHttpClient(params);
        httpClient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
        httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new 
        NTCredentials("username", "passwrd", "host", "domain"));
        HttpPut request = new HttpPut("https://domain/_api/get..");
        request.setHeader("Content-Type", "application/json;odata=verbose");
        request.setHeader("Accept", "application/json;odata=verbose");

        System.out.println(httpClient.execute(request));
    }catch(Exception e){
        throw e;
    }


 RESPONSE 

HTTP/1.1 401 Unauthorized [Server: Microsoft-IIS/8.5,
SPRequestGuid: 6ecb4d9f-9884-c0ba-7e4e-eed562a7e616,
request-id: 6ecb4d9f-9884-c0ba-7e4e-eed562a7e616,
X-FRAME-OPTIONS: SAMEORIGIN,
SPRequestDuration: 4,
SPIisLatency: 0,
WWW-Authenticate: NTLM,
X-Powered-By: ASP.NET,
MicrosoftSharePointTeamServices: 15.0.0.5172,
X-Content-Type-Options: nosniff,
X-MS-InvokeApp: 1;
RequireReadOnly,
Date: Thu,
30 Apr 2020 10:02:57 GMT,
Content-Length: 0] org.apache.http.conn.BasicManagedEntity@679b62af

Solution

  • I got the solution it because of the port and hostname