How to read XF as JSON programmatically?
I have created an XF and generated the Json by appending 'model.json' to the URL. Now, I want to get the same Json when I hit the same URL in servlet. I am getting Error#400 (bad Request) when I use below piece of code. Do I need to pass any authentication to get HTTP connection. If so, what kind of authentication I should you and how to get the authentication params?
HttpURLConnection urlConnection = createHttpConnection(PAGE_URL,null); //Passing Authentication Key as null. See createHttpConnection method below.
String query = "";
urlConnection.setRequestProperty("Content-Length", Integer.toString(query.length()));
urlConnection.getOutputStream().write(query.getBytes("UTF8"));
int status = urlConnection.getResponseCode(); //getting the status code as 400
.
.
.
.
private static HttpURLConnection createHttpConnection(String urlString, String authKey)
throws IOException, ParseException {
URL url = new URL(urlString);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setRequestProperty("Authorization", authKey);
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setConnectTimeout(5000);
urlConnection.setReadTimeout(5000);
LOGGER.info("urlconnection " +urlConnection);
return urlConnection;
}
Thanks,
Nagaraju.