RequestEntity entity = new StringRequestEntity(str, "text/html", "utf-8"); post.setRequestEntity(entity);
最近在做一些爬蟲相關的工作,遇到了一個網站,在使用谷歌開發者工具監控的時候,發現他的請求是這樣的

我們都知道傳統的post請求,所提交的是form data 格式的,key-value鍵值對的形式提交。這個在爬蟲post請求中非常常見。
第一次遇到了這種形式提交的,后面去找了很多方法,發現在百度搜的答案都用不了,后面翻牆去了stackoverflow,這邊貼上地址
http://stackoverflow.com/questions/22671897/httpclient-httppost-and-payload
所給的答案我也用不了。
於是去認真研究了一下,發現他所提交的post流,不是傳統的key-value模型的數據,而是post一段json文字
仔細查看了HttpClient的一些相關的API后,找到了答案
這邊貼上我的小Demo,Demo是用來抓取某個城市的公積金數據的,這邊隱藏去賬號密碼
RequestEntity entity = new StringRequestEntity(str, "text/html", "utf-8"); post.setRequestEntity(entity);
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.RequestEntity; import org.apache.commons.httpclient.methods.StringRequestEntity;
