在很多网址上,都有下一页这个button,而很多都是通过发送post请求来获取参数,今天我们就来看一下post的具体发送方式。
我之前发送一直不成功,原因是在发送json的格式上出了错,我之前写的时候,总是会把双引号改成单引号,导致发送失败。所以按照原来的post请求发送就可以,比如
这个网页的post请求是这样的:
点击view source:
复制
1 {"PageCond/begin":6,"PageCond/length":6,"PageCond/isCount":"true","keywords":"","orgids":"","startDate":"","endDate":"","letterType":"0","letterStatue":"0"}
写成这个样子就可以了
1 Request request = new Request("http://www.beijing.gov.cn/hudong/hdjl/com.web.search.mailList.mailList.biz.ext"); 2 request.setMethod(HttpConstant.Method.POST); 3 request.addHeader("Content-Type", "application/json"); 4 request.addHeader("User-Agent", 5 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"); 6 request.setRequestBody(HttpRequestBody.json("{"PageCond/begin":" + i * 6 7 + ","PageCond/length":6,"PageCond/isCount":"true","keywords":"","orgids":"","startDate":"","endDate":"","letterType":"","letterStatue":""}", 8 "utf-8")); 9 page.addTargetRequest(request);
还有不确定的post请求可以用postman来尝试,postman是个好东西。
这是他的使用方法: