Android&Java解析JS

来源:互联网 发布:淘宝买家信用等级是- 编辑:程序博客网 时间:2024/06/06 13:12
private void parseHtml() throws Exception {        new Thread(new Runnable() {            @Override            public void run() {                String s = "http://xinjinqiao.tprtc.com/admin/main/pro!lrprolist.do";                try {                    URL url = new URL(s);                    HttpURLConnection http = (HttpURLConnection) url.openConnection();                    http.setDoOutput(true);                    http.setDoInput(true);                    http.setRequestMethod("POST");                    http.connect();                    OutputStreamWriter out = new OutputStreamWriter(http.getOutputStream(), "UTF-8");                    // 添加POST请求的参数 格式:A=A&B+B                    String input = "name=flr&nowpage=1&pagesize=10";                    out.append(input);                    out.flush();                    out.close();                    int length = (int) http.getContentLength();                    System.out.println(length);                    BufferedReader reader = new BufferedReader(new InputStreamReader(http.getInputStream()));                    String line;                    StringBuffer buffer = new StringBuffer();                    while ((line = reader.readLine()) != null) {                        buffer.append(line);                    }                    reader.close();                    http.disconnect();                    System.out.println(buffer.toString());                } catch (Exception e) {                    e.printStackTrace();                }            }        }).start();    }
1 0
原创粉丝点击