Midlet与服务器的交互
来源:互联网 发布:傲慢与偏见 知乎 编辑:程序博客网 时间:2024/05/19 20:00
客户端访问服务器无非三种形式,字段较多,字段的值较长较复杂的情况下都应当使用POST方式
HttpConnection httpConn = null;
DataOutputStream dos = null;
try
{
httpConn = (HttpConnection)Connector.open("http://localhost:8088/mail/maildo");
httpConn.setRequestMethod("POST"); //设置请求方式
dos = new DataOutputStream(httpConn.openOutputStream());
dos.writeUTF("write sth...");
dos.writeUTF("write sth..."); //注意写的顺序
dos.close();
httpConn.close();
}
catch(IOException e)
{}
在服务器端可以使用servlet读取请求中的字段
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String uid = request.getParameter("uid"); //
String pwd = request.getParameter("pwd"); //由url中读取的查询字符串
DataInputStream dis = new DataInputStream(request.getInputStream());
String sth1 = dis.readUTF();
String sth2 = dis.readUTF(); //读取的顺序和写入的顺序是一样的
//返回的数据也可以方便读写
DataOutputStream dos = new DataOutputStream(response.getOutputStream());
dos.writeUTF(new Integer(mails.length).toString());
for (int i=0;i<mails.length;i++)
{
dos.writeUTF(sth3);
dos.writeUTF(sth4);//在客户端可以顺序读出sth3,sth4
}
dos.close();
这种方法在客户端需要读取大量重复结构的情况比较方便,可以分别用循环写入和读出,不必使用XML浪费存储空间和处理时间
- Midlet与服务器的交互
- BlackBerry 应用和 MIDlet 之间的交互
- 客户端与服务器的交互
- RFC457_FTP 的服务器与服务器交互
- MIDlet的开发流程与部署
- 客户机与服务器的数据交互
- 客户机与服务器的数据交互
- TCP客户端与服务器的交互过程
- 浏览器与web服务器间的交互
- 实现客户端与服务器的交互
- 浏览器客户端与服务器的交互过程
- 浏览器与服务器的交互图
- 与服务器实时交互的小shell
- 浏览器客户端与服务器的交互过程
- 浏览器与服务器的交互过程
- 客户端与服务器接口的交互。
- golang表单提交与服务器的交互
- 一种与服务器交互的方式
- 现在在做别的事,没有常在这里写博客.
- 一个XML文件...
- Java软件架构设计慨论
- 影响ORACLE汉字显示的字符集问题
- 丫头的前男友!
- Midlet与服务器的交互
- Makefile教程
- EBOOk-搜索引擎
- GCC中文手册
- 完美解决一个事件激活多个函数[KnowSky.com]
- [翻译] PHP的Socket函数参考
- 不要使用VC6自带的STL
- [翻译] PHP和Socket
- macro again, hehe, more details and in chinese