import javax microedition io import java io public class ConnectionMan

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import javax.microedition.io.*;
import java.io.*;
public class ConnectionManager {
protected final String server = "http://no-reg-domain.name"; //такого домена не существует. Когда указан существующий - всё ок
/*
TRACE: <at java.lang.NullPointerException: 0>, Exception caught in Display class
java.lang.NullPointerException: 0
at h.a(), bci=43
at a.commandAction(), bci=315
at javax.microedition.lcdui.ChoiceGroupLFImpl.uCallKeyPressed(), bci=233
at javax.microedition.lcdui.ItemLFImpl.uCallPointerReleased(), bci=56
at javax.microedition.lcdui.FormLFImpl$FormInputHandler.uCallPointerReleased(), bci=113
at javax.microedition.lcdui.AbstractInputHandler.uCallPointerEvent(), bci=84
at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handlePointerEvent(), bci=97
at com.sun.midp.lcdui.DisplayEventListener.process(), bci=346
at com.sun.midp.events.EventQueue.run(), bci=130
at java.lang.Thread.run(Thread.java:744)
*/
protected static HttpConnection conn = null;
protected String requestString = null;
protected String params = "";
public String getContent(String par) {
this.params = par;
Thread t = new Thread(new Runnable() {
public void run() {
try {
conn = (HttpConnection) Connector.open(server + "/" + params);
if(conn.getResponseCode() == conn.HTTP_OK) {
StringBuffer sb = new StringBuffer();
InputStream is = conn.openInputStream();
int ch;
while((ch = is.read()) != -1)
sb.append((char) ch);
requestString = sb.toString();
} else {
requestString = null;
}
}catch(IOException io) {
requestString = null;
}
}
});
t.start();
try{
t.join();
}catch(InterruptedException ie) {
ie.printStackTrace();
}
return requestString.equals("") ? null : requestString;
}
}