0

How to call querybuilder API in Java. I have tried this but i am getting no result. But when i am trying to hit in browser with this URL localhost path then the response is coming properly.

URL url = new URL("http://localhost:4502/bin/querybuilder.json?path=/content");
HttpURLConnection servletConnection = (HttpURLConnection) url.openConnection();
servletConnection.setRequestMethod("GET");
servletConnection.setDoOutput(true);
InputStream response = servletConnection.getInputStream();
Iamat8
  • 3,888
  • 9
  • 25
  • 35

1 Answers1

0

Based on the code shown, most likely you don't have a session established with your localhost. When you hit that URL in a new browser window you will get redirected to a login page where you must first login with appropriate credentials before you can see the page. But when you make the same request via Java code, you haven't provided any credentials. So you won't be able to get to the content.

Check our Preemptive Basic Auth with HttpUrlConnection? for info on how to provide credentials.

Community
  • 1
  • 1
Shawn
  • 8,374
  • 5
  • 37
  • 60