S40手机联网问题
阿冲 2006-11-12 10:34:21 S40手机在获取网页时有部分机型在Connector.open()这句会报空指针异常,,,另一部分机型在获取网页时则一直返回wmlc编码,,,似乎所有的S40机型都有上面两个问题,,,同样的代码在别的机型上则没有任何问题,,,代码如下:
if (this.netType == 0) {
hCon = (HttpConnection) Connector.open("http://10.0.0.172:80" + url.substring(url.indexOf("/" , index)) , Connector.READ_WRITE , true);
hCon.setRequestProperty("X-Online-Host" , serverName);
} else {
hCon = (HttpConnection) Connector.open(url , Connector.READ_WRITE , true);
}
if (checkURL != null) {
hCon.setRequestProperty("Referer" , checkURL);
int i = url.indexOf("xid=") + 4;
hCon.setRequestProperty("xid" , url.substring(i , url.indexOf("?")));
}
this.contentTextBox.setString(serverName + " : " + url);
if (hCon.getResponseCode() == HttpConnection.HTTP_OK) {
this.contentTextBox.setString("HTTP_OK");
is = hCon.openInputStream();
this.contentTextBox.setString("Stream is open");
int len;
byte[] data = null;
byte[] temp = null;
this.contentTextBox.setString("Read data start");
while ((len = is.read(buffer))!= -1) {
if (data == null) {
data = new byte[len];
System.arraycopy(buffer , 0 , data , 0 , len);
} else {
temp = new byte[data.length + len];
System.arraycopy(data , 0 , temp , 0 , data.length);
System.arraycopy(buffer , 0 , temp , data.length , len);
data = temp;
}
}
temp = null;
backContent = new String(data);
}