AEM POST service throws 401 unauthorized
Hi
I am trying to write a post service in aem to which i am sending data in the request body.
To read the data, i have a sling Post servlet where i am expecting to get the data sent by post via request.getReader().
To test this post servlet, i have created another servlet in the same instance which has a doGet() and the following code:
I am hitting this servlet's path in my instance to execute the following code.
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost postRequest = new HttpPost("http://localhost:4502/bin/testingPost"); //the post servlet's path
StringEntity input = new StringEntity("<Comment>hello</Comment>");
input.setContentType("text/xml");
postRequest.setEntity(input);
HttpResponse httpResponse = httpClient.execute(postRequest);
However, i get a 401 in httpResponse while trying to access the post servlet with the path "http://localhost:4502/bin/testingPost".
I have referred a few forums where they have mentioned about removing post from Apache Sling Referer Filter and also about CSRF token but that is of no use.
And also that's not recommended as mentioned in the forums for security reasons.
ex: Apache httpclient post throws resposne status 401 Unauthorized error
However, by making the above configuration in OSGI felix console, i could do an ajax call to my post servlet which was giving me a 403 otherwise but i want to be able to hit the post servlet using the java code mentioned above.
Can you please suggest something as soon as possible.
Thank you.

