Jsoup之提交url

1、url提交表单

        Map<String, String> map = new HashMap<String, String>();
        map.put("stuid", "");
        map.put("pwd", "");
        //如果有跳转(302),会自动跳转
        Document doc = Jsoup.connect(CommonUrl.Login_URL).data(map)
                .timeout(3000).post();
        //获取网页的标题
        String title = doc.title();
        //获取body中的非格式的内容
        String body = doc.body().text();

修改userAgent

,可以防止在手机上访问wap网站

conn.userAgent("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36 SE 2.X MetaSr 1.0");

 

 

2、url设置cookie提交

        Map<String, String> map = new HashMap<String, String>();
        map.put("stuid", "");
        map.put("pwd", "");
        //建立connection
        Connection conn = Jsoup.connect(CommonUrl.Login_URL);  
        //post方法
        conn.method(Method.POST);  
        //表单内容
        conn.data(map);
        //Configures the connection to (not) follow server redirects. By default this is true.
        conn.followRedirects(false);  
        Response response = conn.execute();  
               //获取cookie
        Map<String, String> cookies = response.cookies();  

Done

posted @ 2014-05-07 11:11  行云有影  阅读(974)  评论(0编辑  收藏  举报