我正在使用此代码连接 Servlet。尝试访问互联网时的移动应用程序。
以下消息出现在手机中。
“允许网络访问??是或否”。如果我在诺基亚 6300 中单击该消息的“否”,则会出现“应用程序错误”警告,它会自动关闭应用程序。
我尝试了其他诺基亚手机,如 N70 和 N72。手机不会显示“应用程序错误”。
是手机问题还是编码问题?
有没有使用http连接Servlet的有效方法?
public static InputStream getDataInputStream(String url, String request)
{
HttpConnection httpConnectionObj = null;
OutputStream dataOutputStreamObj = null;
try {
httpConnectionObj = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
httpConnectionObj.setRequestMethod(HttpConnection.POST);
dataOutputStreamObj = httpConnectionObj.openOutputStream();
dataOutputStreamObj.write(request.getBytes());
dataOutputStreamObj.close();
return httpConnectionObj.openInputStream();
} catch (javax.microedition.io.ConnectionNotFoundException cnfe) {
//Alert
} catch (Exception ex) {
//Alert
} finally {
try {
if (httpConnectionObj != null) {
httpConnectionObj.close();
httpConnectionObj = null;
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return null;
}