8月5

jsoup请求网络资源的方式--application/json和x-www-form-urlencoded

| |
16:30Web开发  From: 本站原创
x-www-form-urlencoded方式:

Map<String,Object>  map = new HashMap<>();
map.put("page_size","100")
map.put("ps", "100")
map.put("page_flag", "true")
Document doc = Jsoup.connect("http://www.zgetfl.org/qget/main_qget/sqgl/apLcChildAction.do?method=listApLcChildnew")
                    .header("useragent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36")
                    .header("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
                    .data("page_size","100")
                    .data("ps", "100")
                    .data("page_flag", "true")
                    .post();

application/json方式:

Map<String,String> map = new HashMap<>();
map.put("username","aaaa");
map.put("password","123456");
Gson gson = new Gson();
String parameter = gson.toJson(map);
Document doc = Jsoup.connect("localhost:8080/api/user/login")
                    .header("useragent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36")
                    .requestBody(parameter)
                    .ignoreContentType(true)
                    .post();

来源:Heck's Blog
地址:https://www.heckjj.com/post/511/
转载时须以链接形式注明作者和原始出处及本声明,否则将追究法律责任,谢谢配合!
阅读(50) | 评论(0) | 引用(0)