I was having a problem in accessing the contents of the url ,when i was trying to call the url from java application.I can access other sites through my program but not the stack exchange site. But i can call the url directly from the browser and get data. But i want the output from my program. this is my program and output is is encrypted form.I want to get in a normal format. import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.io.BufferedReader;
public class URLServlet {
public static void main(String[] args) {
try {
URL urldemo = new URL("http://api.stackexchange.com/2.1/questions/1346?site=health.stackexchange.com&filter=withbody");
URLConnection yc = urldemo.openConnection();
yc.setDoOutput(true);
System.out.println(yc.getContent());
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}catch(Exception e) {
System.out.println(e);
}
System.out.println("hello world");
}
}