import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class DesktopApp {
public static String onLed(String url){
StringBuffer sb=null;
try {
URL u = new URL(url + "LED=ON");
HttpURLConnection h = (HttpURLConnection) u.openConnection();
h.setReadTimeout(45000);
h.setDoInput(true);
h.setDoOutput(true);
System.out.println(h.getResponseCode());
if (h.getResponseCode() == 200) {
BufferedReader br = new BufferedReader(new InputStreamReader(h
.getInputStream()));
String text = br.readLine();
sb = new StringBuffer();
while (text != null) {
sb.append(text + "\n");
text = br.readLine();
}
}
}catch(Exception e){
}
return sb.toString();
}
public static String offLed(String url){
StringBuffer sb=null;
try {
URL u = new URL(url + "LED=OFF");
HttpURLConnection h = (HttpURLConnection) u.openConnection();
h.setReadTimeout(45000);
h.setDoInput(true);
h.setDoOutput(true);
System.out.println(h.getResponseCode());
if (h.getResponseCode() == 200) {
BufferedReader br = new BufferedReader(new InputStreamReader(h
.getInputStream()));
String text = br.readLine();
sb = new StringBuffer();
while (text != null) {
sb.append(text + "\n");
text = br.readLine();
}
}
}catch(Exception e){
}
return sb.toString();
}
}
No comments:
Post a Comment