Android中的请求

一、java中的Socket服务端开发

try {

            ServerSocket ss = new ServerSocket(8888);

            while (true) {

                Socket socket = ss.accept();

                DataOutputStream dout = new DataOutputStream(

                        socket.getOutputStream());

                Date d = new Date();

                dout.writeUTF(d.toLocaleString());

                dout.close();

                socket.close();

            }

        } catch (IOException e) {

            e.printStackTrace();

    }

二、java中的Socket客户端开发

    try {

            Socket s = new Socket("172.20.10.3",8888);

            DataInputStream din = new DataInputStream(s.getInputStream());

            String msg = din.readUTF();

            System.out.println(msg);

        } catch (IOException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

}

三、 通过URI获取网络中的资源

try {

            URL url = new URL(u);

           

            URLConnection conn = url.openConnection();

            InputStream in = conn.getInputStream();

            BufferedInputStream bis = new BufferedInputStream(in);

            int len = 0;

            while((len=bis.read())!=-1) {

                //读取

        }

}

四、HttpPost

 

 

posted @ 2013-07-03 19:52  des.pmx  阅读(318)  评论(0)    收藏  举报