0

I am connecting to SharePoint to query lists, all was well but now I get a HTTP/1.1 500 Internal Server Error for the same request which was ok and tested. I guess the problem is from a configuration.

The response I get is

The Web application at http://hostname:80/my/personal/incorta/_api/web/lists could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

I was following https://stackoverflow.com/questions/29570383/basic-authentication-from-java-to-sharepoint-2013-rest-api/29609502#29609502 and I was getting the correct response my code as follow

    CredentialsProvider credsProvider = new BasicCredentialsProvider();      
    credsProvider.setCredentials(
            new AuthScope(AuthScope.ANY),
            new NTCredentials("USERNAME", "PASSWORD", "https://HOSTNAME", "DOMAIN"));

    CloseableHttpClient httpclient = HttpClients.custom()
            .setDefaultCredentialsProvider(credsProvider)
            .build();

    try {
        HttpGet httpget = new HttpGet("http://hostname/_api/web/lists");
        httpget.setHeader("Accept", "application/json;odata=verbose");

        System.out.println("Executing request " + httpget.getRequestLine());
        CloseableHttpResponse response = httpclient.execute(httpget);

        try {
            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());             
            BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

            StringBuffer result = new StringBuffer();
            String line = "";
            while ((line = rd.readLine()) != null) {
                result.append(line);
            }

            System.out.println(result);

            EntityUtils.consume(response.getEntity());
        } finally {
            response.close();
        }
    } finally {
        httpclient.close();
    }   
0

Try to access the rest api in browser directly to check if it work.

And add user account to the WSS_ADMIN_WPG group on the server.

And check if you config AAM in SharePoint server.

If you want to access content from SharePoint on-premise using Java, here is a solution for your reference.

Solution: Java Sharepoint REST API

0
  1. Even when using SharePoint on-prem you should be using HTTPS not HTTP. It also appears that you are using a non-canonical host name as your host name for your SharePoint server. Even if your local environment uses the .local suffix, you should be using it. SharePoint stopped supporting single name host names some time ago.
  2. I highly suspect that your environment has been updated and/or re-configured to use only HTTPS. Because of the port number’s presence in the error output.
  3. What version of on-prem SharePoint are you using?

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.