public static String getDataJson(String url, Integer pageNo, Integer pageSize, String search) {
HttpPost httpPost = null;
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
httpPost = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(30000).setConnectTimeout(30000).build();//设置请求和传输超时时间
httpPost.setConfig(requestConfig);
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("pageNo", pageNo.toString()));
list.add(new BasicNameValuePair("pageSize", pageSize.toString()));
list.add(new BasicNameValuePair("search", search));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list,"utf-8");
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
if(response != null){
HttpEntity resEntity = response.getEntity();
HTTPClient获取接口数据返回JSON
最新推荐文章于 2022-10-19 16:17:19 发布