首页 > 编程学习 > 备份:HttpClient 4.x POST请求
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);
            }

641 total views, 1 views today

本文地址:https://blog.wizzer.cn/archives/3287 , 转载请保留.

本文目前尚无任何评论.

发表评论