我想获取网页的源代码。我正在使用HttpConnection
以下是我的代码..
HttpConnection c = null;
InputStream dis = null;
StringBuffer raw = new StringBuffer();
try {
c = (HttpConnection)Connector.open(txtUrl.getText().toString());
int len = 0;
int size = 0;
dis = c.openInputStream();
byte[] data = new byte[256];
while ( -1 != (len = dis.read(data)) ){
raw.append(new String(data, 0, len));
size += len;
}
System.out.println("Html source"+raw.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Exception " +e);
}
finally {
if (dis != null)
try {
dis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Exception " +e);
}
if (c != null)
try {
c.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Exception " +e);
}
}
在此行dis = c.openInputStream();
我收到错误,因为找不到源 - datagramProtocol(ConnectionBase).receive(Datagram)。
我出错的地方请纠正我..