In Blogger post I have this snippet
<applet codebase="https://droidsnip.googlecode.com/hg/" height="300" archive="text.jar" width="300" code="Google.class">
and have this java code stored at google code:
public class Google extends java.applet.Applet {
public static void main() {
}
public void paint(Graphics g) {
String result = sendGetRequest(
"http://www.google.com", null);
g.drawString(result, 30, 30);
}
public static String sendGetRequest(String url,
String requestParameters) {
String result = null;
if (url.startsWith("http://")) {
try {
URL url1 = new URL(url);
URLConnection conn = url1.openConnection();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
result = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
}
And i do not get any result in post, but I get a normal html response using Eclipse.
What can be a problem with Blogger?
Btw, if I just use
g.drawString("test", 30, 30);
I get a string on the post, so it works
Unsigned Java applets are restricted in what they can do to prevent malicious use. If your applet isn’t signed, then it can only connect to the server on which it is hosted (i.e. droidssnip.google.com in this case).
Here’s a reference on how to sign an applet. Note that if you use a self-signed certificate (one you generate yourself with keytool), then you’ll be prompted with a security warning when the applet runs. To avoid this, you’ll need a certificate from a trusted Certificate Authority.