HttpConnection hc =null;
DataInputStream is=null; // hc.openInputStream();
StringBuffer str = new StringBuffer();
try
{
hc =(HttpConnection) Connector.open(url);
is = new DataInputStream(hc.openDataInputStream());
int ch;
while ((ch=is.read())!=-1)
{
str.append((char) ch);
}
}
catch(Exception e)
{
e.printStackTrace();
str.append("open Error");
}
finally
{
try
{
if (is!=null) is.close();
if (hc!=null) hc.close();
}
catch(IOException ioe)
{
ioe.printStackTrace();
str.append("close Error");
}
}
return str.toString();
}
在模拟器无法取得数据,在真机上也无法取得数据。
真机上[JAVA应用]-[设置]-[默认连接]-CMWAP和CMNET都测试过,依然无法取得数据
有些没有数据返回,有些返回的数据为<html><head><title>Error</title></head><body>The parameter is incorrect.</body></html>
url="www.abkk.com"返回上述回应
url="www.yahoo.com"则没有返回,
为什么会这样?
sun 的 文档 不过是 j2se 的。http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html
http.keepAlive (default: true)
Indicates if keep alive (persistent) connections should be supported. Persistent connections improve performance by allowing the underlying socket connection be reused for multiple http requests.
The default is true and thus persistent connections will be used with http 1.1 servers. Set to 'false' to disable the use of persistent connections.