java clientrequest_java httpclient 带request参数请求

CloseableHttpClient httpClient = HttpClients.createDefault();// 创建http实例

CloseableHttpResponse response = null;

HttpGet httpGet =new HttpGet(url);

/*httpPost.setHeader("Referer","http://oms.hqygou.com/order/temp/new");

httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

httpPost.setHeader("X-Requested-With","XMLHttpRequest");

httpPost.setHeader("Cookies",cookies);*/

/*HttpHost proxy =new HttpHost("125.118.79.44", 6666);

RequestConfig config = RequestConfig.custom().setProxy(proxy).build();

httpGet.setConfig(config);*/

//RequestConfig config = RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(10000).build();//设置请求和传输超时时间

//httpGet.setConfig(config);

httpGet.setHeader("Connection","keep-alive");

httpGet.setHeader("Content-Type","application/html; charset=UTF-8");

httpGet.addHeader(new BasicHeader("Cookie", cookie));

response = httpClient.execute(httpGet);

HttpEntity entity = response.getEntity(); //请求类型

//System.out.println(entity.getContentType());//

String content = EntityUtils.toString(entity, "utf-8");

///

response.close();

httpClient.close();

这篇写的更好

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值