Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

java发送post form_data请求

List headers = new ArrayList();
headers.add(new BasicHeader("User-Agent", "Mozilla/5.0(Windows NT 6.1;Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0"));
headers.add(new BasicHeader("referer", "https://weibo.com/tv/billboard"));
headers.add(new BasicHeader("cookie", "SUB=_2AkMokY13f8PxqwJRmP0Xz27hZYR-wgrEieKezXysJRMxHRl-yT9kqlEttRB6AxGjmB_oIUP7hTf42y1NYgzmxwF3nr3X; YF-V-WEIBO-G0=b09171a17b2b5a470c42e2f713edace0; _s_tentry=-; Apache=375387657023.476.1607406605269; SINAGLOBAL=375387657023.476.1607406605269; ULV=1607406605393:1:1:1:375387657023.476.1607406605269:; XSRF-TOKEN=8e5cfPVMjH-y_FK637dfbXPr"));
HttpPost post = new HttpPost(url);
HttpClientBuilder httpClient = HttpClientBuilder.create().setDefaultHeaders(headers);
CloseableHttpResponse response = httpClient.build().execute(post);
HttpEntity httpEntity = response.getEntity();
ResponseBody = EntityUtils.toString(httpEntity, "utf-8");

这个是我写的一个post 请求,但是还有一个参数 form_data不知道放在哪
下面是form_data 相关数据

data: {"Component_Billboard_Billboardcategory":{},"Component_Billboard_Billboardlist":{"cid":"4418213501411061","count":20}}

这个是data 表单 放哪里合适呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
post.setEntity(new StringEntity(data));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...