We are using SharePoint 2016 for storage and retrieval of files. And using java httpclient class to do it. Now we are using following API to check whether folder is already present.
String folderURI = "/_api/Web/GetFolderByServerRelativeUrl('" + "/<document library/folderpath>" + "')";
e.g : folderpath = test1/type/2007
Following is the code to contact SharePoint and get it's response.
HttpGet httpget = new HttpGet(finalURL);
httpget.setHeader("Content-Type", "application/octet-stream");
httpget.setHeader("X-HTTP-Method", requestMethod);
httpget.setHeader("Cookie", "rtFa="YqLvkl";FedAuth="uZnxt");
response = httpClient.execute((HttpUriRequest) httpget);
If the folder already present, I'm getting 200 ok as response, which is correct. But if folder not present, I'm getting 500 internal server error. instead of this,I should get 404 Not Found. What am I missing. how come for the same API, I'm getting one correct response(folder present 200 ok) and one internal server error(folder not present 500).