I am calling Assembla REST Api with basic authentication using the following code. I get html output instead of xml. I want to use this output data in my program but not able to fetch it from html format. Please suggest how to get output in xml format.
HttpURLConnection conn = null;
String authentication = "username:password";
String encoding = Base64.encodeToString(authentication.getBytes(), Base64.NO_WRAP);
URL url = new URL("https://www.assembla.com/spaces/my_spaces");
//URL url = new URL("https://www.assembla.com/");
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type","Accept: application/xml; charset=utf-8");
conn.setRequestProperty("Authorization", "Basic " + encoding);
conn.setDoOutput(true);
conn.connect();
System.out.println(conn.getResponseCode());
System.out.println(conn.getResponseMessage());
InputStreamReader isr =
new InputStreamReader(conn.getInputStream());
BufferedReader br = new BufferedReader(isr);
String inputLine;
while ((inputLine = br.readLine()) != null)
System.out.println(inputLine);
br.close();
also i tried to convert this output into jsonObject but got the error org.json.JSONException:Value
InputStreamReader isr =
new InputStreamReader(conn.getInputStream());
BufferedReader br = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
String inputLine;
while ((inputLine = br.readLine()) != null){
System.out.println(inputLine);
sb.append(inputLine);
}
try {
JSONObject user = new JSONObject(sb.toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}