Android学习之Http使用Post方式进行数据提交(3)

        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 

        byte[] data = new byte[1024]; 

        int len = 0

        String result = null

        if (inputStream != null) { 

            try { 

                while ((len = inputStream.read(data)) != -1) { 

                    byteArrayOutputStream.write(data, 0, len); 

                } 

                result = new String(byteArrayOutputStream.toByteArray(), encode); 

            } catch (IOException e) { 

                e.printStackTrace(); 

            } 

        } 

        return result; 

    } 

 

    /** 

     * @param args 

     */ 

    public static void main(String[] args) { 

        Map<String, String> map = new HashMap<String, String>(); 

        map.put("username", "admin"); 

        map.put("password", "123456"); 

        String result = sendPostMessage(map, "UTF-8"); 

        System.out.println(">>>" + result); 

    } 

 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/03bcfb6192046f895d539878d1b39975.html