2016八月16
备份:HttpClient 4.x POST请求
List<BasicNameValuePair> formParams = new ArrayList<>(); formParams.add(new BasicNameValuePair("urlpp", "")); formParams.add(new BasicNameValuePair("urlkm", "")); formParams.add(new BasicNameValuePair("khjb", "2")); HttpEntity httpEntity = new UrlEncodedFormEntity(formParams, "UTF-8"); HttpPost httpPost = new HttpPost(tesseract.njwztx_baseUrl + "fetchNextList.action"); httpPost.setEntity(httpEntity); httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); httpPost.setHeader("X-Requested-With", "XMLHttpRequest"); httpPost.setHeader("Cookie", "rememberPhone=1; phoneNumber=" + tesseract.getNjwztx_dhhm() + "; friendlyReminder=true;JSESSIONID=" + JSESSIONID + ";"); HttpClient httpclient = HttpClients.createDefault(); HttpResponse response = httpclient.execute(httpPost); HttpEntity entity = response.getEntity(); Header[] headers = response.getAllHeaders(); for (int i = 0; i < headers.length; i++) { log.debug("header" + i + ":::" + headers[i]); } if (entity != null) { log.debug("getContentEncoding:::" + entity.getContentEncoding()); log.debug("getContentType:::" + entity.getContentType()); String str = EntityUtils.toString(response.getEntity()); log.debug(str); Files.write("2.html", str); }
本文地址:https://wizzer.cn/archives/3287 , 转载请保留.