微信 将要访问问 http://112.78.26.19?n

Title请访问N桌网 http://bbs. N桌面终极皮肤|N桌面序列号|N桌面软件更新|专业致力于N桌面终极皮肤的制作与分享 - Powered
& meta & Description请访问N桌网 http://bbs. N桌面终极皮肤官方论坛专业致力于N桌面终极皮肤的制作与分享,N桌面软件的更新下载,N桌面序列号的购买,N桌面终极皮肤的下载,N桌面软件售后交流中心,手机软件、手机游戏、手机主题、电子书、手机图铃的免费下载分享,全球最大的综合智能手机中文论坛 & meta & KeywordsN桌面, N桌面论坛, ndesk, 安卓软件下载, 终极皮肤下载, N桌面序列号, N桌面售后, 手机软件, 手机游戏, 手机主题, 电子书, 手机图铃Keywords hit in search results
|冰点还原 ◆腾讯微博 ☆更多皮肤 自带的所有终极 98精简安娜图标版 against alain analysis antivirus badware beijing build312 ccarpet change china clbhsclmbr community complete content design desnudas diy版本n桌面2 dxnurotrq facebook fotos fraud freeze google guangzhou itrack kellicarricophotography livejournal marionrek microblog misschasse mujeres ndesk ndesktop ndesk破解版 norton n桌面ndesk2 n桌面qq群:6548371 n桌面皮肤下载 n桌面终极皮肤官方网站 n桌面软件官方网站 online overall pageviews pixnet prayandsing reputation review reviews roiters s60v5 safebrowsing safeweb shanghai shenzhen sitetrail skins tencent thread tramer trust tumblr type中规定 unhbntjxzq users website webutation zendesk 冰点还原企业版 去除n桌面2 塞班s60v5 官网:http 本文来自n桌面论坛:http 此版本部分图标来自mer 特此感谢mer 状态栏图标不 论坛:http 隆重登场! 零售完整版
Search Engine Recommended Keywords, , , ,
Home, , Myspace, Stardoll Com,
Captured Content N桌面终极皮肤 N桌面序列号 N桌面软件更新 专业致力于N桌面终极皮肤的制作与分享 - Powered . 你可以 注册一个帐号,并以此 登录,以浏览更多精彩内容,并随时发布观点,与大家交流。 查看新贴. ksmz5pVp -
12:56. / 340 -
17:17. cltcwzh -
15:12. liuge1983 -
00:45. / 40 -
23:25. Dana0904 -
17:56. asd960112 -
01:41. pwxotjlhh -
14:02. / 962.369f6369o2 -
00:32. 分区版主: 小祭, 呵呵 追清风. / 527. -
08:44. Dana0904 -
17:39. hwud7cEe -
19:00. dkded8nJe -
15:05. pwxotjlhh -
14:01. bsxq6eZs -
02:01. GMT 8,
18:51. 免责声明 本论坛由论坛管理人 admin 运营,任何关于本论坛的争议与纠纷请通过本论坛提供的联系方式与论坛管理人联系。. Captured Keywords免费急速注册 登录, 购买授权, , 昨日, , 会员, n桌面相关产品交流专区ndesk products, 产品发布products release, 终极皮肤ultimate skins, 讨论交流communications, 问答专版faq, n桌面论坛塞班手机资源专区, 塞班精品软件symbian software, 强调精品两个字, 夕醉星辰, 塞班炫彩主题theme, 塞班休闲游戏games, 塞班电子书版ebook, 塞班综合超版composite, n桌面终极皮肤官方论坛管理专区management, 公告活动announcement, 红包中心red packets, 勋章大厅medal, 签到中心sign in, 投诉专版complaint, 其他事务others, n桌面论坛日常事务办理专版, 回收站recycling station, 分区 简介, 不正常的帖子回收站, 私密版块, 友情链接, 天天动听, 论坛导航, n桌网址导航, 塞班论坛, 站长工具, 安全管家, 墨迹天气, uc软件, 手机乐园, 天网手机软件, 备用论坛, 顺君网址, 我的领地, 官方博客, 腾讯微博, 新浪微博, qq空间, 友链申请, 账号发放中心, 社区银行, 领取红包, 休闲游戏, 打折机票, 淘宝购买, 财付??购买, 序列号找回, 联系我们, archiver, 侵权投诉
%Sub Domain:% of PageViewsPageViews per User8.73%7.69%3.90.25%2.07%372.54%1.99%3.51.06%1.56%6.60.09%1.48%700.34%1.46%190.24%1.23%230.14%1.13%370.12%1.05%410.93%0.99%4.80.26%0.97%160.19%0.87%201.05%0.86%3.71.38%0.83%2.70.22%0.81%170.30%0.77%110.39%0.76%90.15%0.74%210.57%0.73%5.70.42%0.73%7.80.17%0.69%180.29%0.66%100.31%0.60%90.24%0.58%111.52%0.57%1.60.52%0.56%4.80.39%0.56%6.40.34%0.55%7.20.14%0.54%170.36%0.54%6.70.33%0.51%70.09%0.51%250.11%0.51%200.28%0.51%80.65%0.50%3.50.62%0.49%3.60.44%0.49%50.56%0.49%3.90.10%0.48%210.21%0.47%100.08%0.46%250.21%0.46%100.58%0.46%3.60.11%0.45%180.07%0.44%290.17%0.43%110.23%0.41%80.37%0.40%4.80.20%0.37%80.33%0.35%4.80.34%0.35%4.50.28%0.34%5.50.29%0.34%5.10.22%0.33%70.16%0.32%90.46%0.31%30.16%0.31%90.62%0.31%2.20.42%0.31%3.30.31%0.30%4.40.14%0.30%90.09%0.29%150.07%0.28%180.45%0.28%2.80.16%0.28%80.95%0.28%1.30.25%0.28%4.80.23%0.28%5.20.11%0.27%110.14%0.27%90.09%0.27%130.22%0.26%5.40.07%0.26%150.21%0.25%5.40.08%0.25%150.11%0.25%100.34%0.25%3.30.48%0.25%2.30.28%0.25%40.22%0.25%4.90.37%0.25%30.07%0.24%150.23%0.24%4.60.12%0.24%90.13%0.23%70.71%0.22%1.40.16%0.22%60.09%0.21%100.23%0.21%4.10.10%0.21%90.15%0.20%60.17%0.19%4.80.08%0.18%100.18%0.18%4.50.33%0.18%2.40.07%0.18%120.20%0.17%40.08%0.17%100.14%0.17%60.21%0.17%3.50.31%0.17%2.40.15%0.17%50.17%0.16%4.30.09%0.16%80.19%0.16%3.80.05%0.16%130.11%0.15%60.07%0.15%100.06%0.15%100.12%0.15%60.12%0.15%50.17%0.15%3.80.17%0.14%3.70.28%0.14%2.20.07%0.14%90.06%0.13%90.15%0.13%3.80.59%0.13%10.09%0.13%70.06%0.13%100.19%0.13%30.08%0.13%70.07%0.12%80.14%0.12%3.80.12%0.12%40.07%0.12%70.15%0.12%3.50.14%0.12%3.60.09%0.11%6
0.09%0.11%60.09%0.11%60.10%0.11%50.07%0.11%60.13%0.11%3.70.15%0.10%3.10.19%0.10%2.50.03%0.10%140.06%0.10%70.10%0.10%40.17%0.10%2.50.14%0.09%3.10.07%0.09%60.18%0.09%2.10.08%0.09%50.19%0.09%20.06%0.09%70.14%0.09%2.80.09%0.08%40.33%0.08%1.10.35%0.08%1.10.14%0.08%2.70.10%0.08%30.08%0.08%50.11%0.08%3.30.11%0.08%3.30.11%0.08%30.08%0.08%40.07%0.08%50.30%0.07%1.10.06%0.07%50.10%0.07%3.10.10%0.07%3.20.32%0.07%10.06%0.07%50.15%0.07%2.10.13%0.07%2.30.09%0.07%40.08%0.07%40.06%0.07%50.17%0.07%1.80.07%0.07%40.06%0.07%50.10%0.07%2.80.18%0.06%1.60.12%0.06%2.30.07%0.06%40.14%0.06%1.90.08%0.06%3.40.07%0.06%40.05%0.06%50.22%0.06%1.20.12%0.06%2.10.11%0.06%2.30.13%0.06%1.90.12%0.06%2.20.05%0.06%50.12%0.06%2.20.06%0.06%40.12%0.06%2.10.12%0.06%20.12%0.06%2.10.09%0.05%2.70.06%0.05%40.08%0.05%30.06%0.05%40.13%0.05%1.80.07%0.05%3.20.06%0.05%40.05%0.05%40.06%0.05%40.12%0.05%20.18%0.05%1.20.22%0.05%10%34.21%0
unhbntjxzq.pixnet.net #840; dxnurotrq.pixnet.net #849; itrack.it #2,290; marionrek.livejournal.... #72; n- #1,117;
n- #1,117; ar- #2; .... #81; up.no #2,487;
#900; clbhsclmbr.cz.cc #542
/tramer.org.tr
... n-ble.net-n----n-change.biz-n-change.net-n-community.de---n-da.jp-n--n--n-din ...http://www.webutation.net/sites/n
... Q Q●-== →
-= ==-◆腾讯微博(Tencent MicroBlog)◆-== =- /ndesktop-= ==-☆更多皮肤(More Skins)☆-== → http://n--= 下载 ...http://www.n-desk.net/author.jsp?skinName=StarShineOVI.sisx&skinId=1&ovi=true
Reviews: Google Safebrowsing: Website Antivirus: Norton Safeweb. WoT (Web of Trust): ... n- - 90%http://www.webutation.net/go/review/fotos-de-
1.此版本部分图标来自Mer Wong (http://n-/thread-.html) 的补丁包。特此感谢Mer_Wong。 2.去除N桌面2.6自带的所有终极 ...http://bbs./thread-881-1-1.html
http://n-/...Deep Freeze Ent.下载v6.61.20.2822 中文版(破解版)|冰点还原... 冰点还原企业版 Deep Freeze Ent.下载v6.61.20....Type中规定 .../ndesk%E7%A0%B4%E8%A7%A3%E7%89%88-2011.html
N桌面QQ群:6548371 论坛:http://n- 官网:http://www.n-desk.net/ndesk.html
门户 N桌面终极皮肤官方网站; 官网 N桌面软件官方网站; 首页 ... 本文来自N桌面论坛:http://n-http://bbs./thread-419-1-1.html
Users City Rank in City % of overall PageV 17.0%: Beijing (China) 176: 14.5%: 8.4%: Shanghai (China) 186: 7.0%: 5.8%: Shenzhen (China) 165: 6.0%: 5.5%: Guangzhou .../n-
No Coupons found for this website.
Write a review for the website ...
500 characters left
Your Review:
(5 out of 5)
Server InformationIP Address: 119.57.62.83
Server:nginx/1.2.9
Powered By:PHP/5.2.10
Traffic% of Internet UsersReach 888 0.128% 989 975 0.126% 1,030 970 0.1288% 1,002 955 0.1306% 989PageViews% of Internet PageViewsPage Views Per User 965 0.0063% 5.4 1,097 0.00531% 4.82 1,160 0.00504% 4.46 1,156 0.00509% 4.45
UsersCountryRank Within Country% of overall PageViews92.7%China14894.1%1.4%Japan5,6310.8%1.4%Taiwan6341.7%1.3%Hong Kong4011.1%0.6%USA45,9310.3%2.6%Other Countries~2.1%
UsersCityRank in City% of overall PageViews17.0%Beijing (China)17614.5%8.4%Shanghai (China)1867.0%5.8%Shenzhen (China)1656.0%5.5%Guangzhou (China)1514.7%2.7%Hangzhou (China)1862.1%2.1%Chengdu (China)1692.3%2.1%Wuhan (China)1422.3%1.8%Hefei (China)1283.7%1.8%Xian (China)2431.6%1.8%Jinan (China)1212.2%1.7%Nanjing (China)1931.4%1.6%Zhengzhou (China)1641.5%1.6%Suzhou (China)972.9%1.4%Chongqing (China)2921.2%1.4%Changsha (China)1251.4%1.4%Fuzhou (China)803.9%1.2%Qingdao (China)1271.2%1.2%Nanning (China)1220.7%1.1%Dongguan (China)2060.8%1.1%Tianjin (China)1371.1%0.9%Xiamen (China)2520.6%0.9%Shenyang (China)1690.6%0.9%Central District (Hong Kong)4370.7%0.8%Putian (China)2620.8%0.8%Shijiazhuang (China)1420.7%0.8%Foshan (China)1380.7%0.7%Kunming (China)1430.8%0.7%Dalian (China)1630.6%0.7%Harbin (China)1331.0%0.6%Changchun (China)1041.0%0.6%Taipei (Taiwan)8820.5%0.6%Nanchang (China)1200.7%0.6%Zhuhai (China)1020.7%0.6%Taiyüan (China)1670.3%0.5%Ningbo (China)2350.5%0.4%Wenzhou (China)2250.4%0.4%Seoul (South Korea)3,8650.1%0.4%Guiyang (China)680.6%0.4%Shantou (China)1090.5%0.4%Quanzhou (China)1660.3%0.3%Lanzhou (China)1230.2%0.3%Changzhou (China)1710.2%0.3%Xuzhou (China)881.5%0.3%Zhuzhou (China)321.0%0.3%Wuxi (China)4920.2%0.3%Choucheng (China)2470.2%0.3%Zhangdian (China)1450.1%0.3%Oita (Japan)2270.1%0.2%Hengshui (China)640.4%0.2%Haikou (China)1340.2%0.2%Osaka (Japan)1,9730.2%0.2%Taichung (Taiwan)5030.1%0.2%Hebei (China)1650.3%0.2%Guilin (China)2030.1%0.2%Yantai (China)2640.1%0.2%Yichang (China)480.9%0.2%Singapore (Singapore)2,4170.1%0.2%Zhongshan (China)2460.1%0.2%Xian (China)840.2%0.2%Chaoyang (China)1360.2%0.2%Linyi (China)1930.1%0.2%Binzhou (China)410.3%0.2%Kaifeng (China)580.2%0.2%Tokyo (Japan)14,7960.1%0.2%Bagnolo Mella (Italy)20.7%0.2%Dezhou (China)1130.2%0.2%Weifang (China)2800.1%0.2%Langfang (China)1530.1%0.2%Zhanjiang (China)1210.2%0.2%Los Angeles, CA (USA)20,2860.1%0.2%Hsinchu (Taiwan)1230.8%0.2%Maanshan (China)4530.1%0.2%Handan (China)810.2%0.2%Qingyuan (China)960.1%0.2%San Francisco, CA (USA)11,8170.1%0.2%Meizhou (China)1390.1%0.2%Ürümqi (China)3430.1%0.2%Rongcheng (China)290.6%0.2%Wuhu (China)1380.2%0.1%Yangshe (China)340.5%0.1%Liaocheng (China)1670.1%0.1%Maoming (China)1270.2%0.1%Guanyang (China)200.1%0.1%Jiangmen (China)950.3%0.1%Huizhou (China)3850.0%0.1%Anyang (China)1100.1%0.1%Yuncheng (China)770.1%0.1%Luoyang (China)4120.1%0.1%Baoding (China)2610.2%0.1%New York, NY (USA)27,3000.1%0.1%Yangzhou (China)3150.0%0.1%Jinhua (China)2780.1%0.1%Yangjiang (China)460.4%0.1%Henan (China)3510.0%0.1%Tangshan (China)2290.1%0.1%Nantong (China)4240.1%0.1%Kowloon (Hong Kong)3280.1%0.1%Shaoyang (China)810.3%0.1%Zhenjiang (China)1610.1%0.1%Weinan (China)1410.0%0.1%Kuala Lumpur (Malaysia)4,0580.1%0.1%Wuzhou (China)1380.1%13.7%OTHER ~11.5%
Site Disclaimer:
All trademarks are the property of their respective owners. The facts, figures, reviews, records, stats, and other data presented on this page is for suggestion and information purposes only. AnswerMe.org is not responsible for any incorrect or incomplete information. AnswerMe.org does not take responsibility for any user-reviews of websites inside its resource and reserves the right to keep or remove those. It is highly recommended that you review all the data for accuracy.HttpClient通过post和get方法获取网页html代码
最后更新时间
HttpClient通过post和get方法获取网页html代码
package com.demo.httpClinet;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStreamWriter;import java.util.ArrayList;import java.util.List;import org.apache.http.HttpEntity;import org.apache.http.HttpResponse;import org.apache.http.NameValuePair;import org.apache.http.client.HttpClient;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpPost;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.message.BasicNameValuePair;import org.apache.http.util.EntityUtils;public class Test { /**
* @param args
* @throws Exception
*/ public static void main(String[] args) throws Exception {
String url
= &http://localhost:8080/news/new/toList.do&;
//创建默认的 HttpClient 实例
HttpClient httpClient = new DefaultHttpClient();
// 2 创建httpPost
HttpPost httpPost = new HttpPost(url);
//3 简单名称至对节点类:
List&NameValuePair& formParams = new ArrayList&NameValuePair&();
BasicNameValuePair pair = new BasicNameValuePair(&newsTitle&, &八位&);
formParams.add(pair);
// 4 post传递参数
//POST则需要通过NameValuePair类来设置参数名称和它所对应的值
//5 UrlEncodedFormEntity 模拟提交表单:
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formParams, &UTF-8&);
//6 httppost.setEntity(UrlEncodedFormEntity);//提交表弟那
httpPost.setEntity(urlEncodedFormEntity);//提交表单
7 执行post请求,返回httpResponse = HttpClient.execute(httppoar);
HttpResponse httpResponse = null;
httpResponse = httpClient.execute(httpPost);
//8 获取相应实体:httpEntity = httpResponse.getEntity();
HttpEntity entity = httpResponse.getEntity();
//9获取相应内容:EntityUtils。toString(httpEntity);
String pageContent = EntityUtils.toString(entity, &gbk&);
System.out.println(&----------------------------------------&);
System.out.println(pageContent);
System.out.println(&----------------------------------------&);
//关闭连接,释放资源
httpClient.getConnectionManager().shutdown(); }
public static void
createHtml()throws Exception {
String pageContent
null;//网页文件内容
String url
= &http://localhost:8080/news/news/.html&;//请求的网址
pageContent = getHTML(url);//获取网址内容
String filePath = &/&;//路径
String fileName = &123.HTML&;
String enc = &GBK&;
System.out.println(&pageContent = &+pageContent);
buildJavaFile(filePath,fileName,pageContent,enc);
public static String getHTML(String url) throws Exception {
//创建HttpClient
HttpClient httpclient = new DefaultHttpClient();
String pageContent = null;
//创建httpGet
HttpGet httpget = new HttpGet(url);
//执行get请求,返回httpResponse
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();//
EntityUtils。toString(httpEntity);
pageContent = EntityUtils.toString(entity, &gbk&);
System.out.println(&----------------------------------------&);
System.out.println(pageContent);
} finally {
httpclient.getConnectionManager().shutdown();
return pageContent; }
public static
void postTest(){
* 讲inputStream转换为字符串
* @param in
* @throws IOException
*/ public static String inputStream2String(InputStream in) throws IOException {
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = in.read(b)) != -1;) {
out.append(new String(b, 0, n));
return out.toString(); } /**
* 创建文件
* @param filePath
* @param content
* @param enc
*/ public static boolean buildJavaFile(String filePath, String fileName,String content,String enc) {
String paths = System.getProperty(&user.dir&);
String endPath = paths+&/src/&+filePath;
String newFilePath
= endPath + &/&+fileName;
File file = new File(newFilePath);
//创建文件夹
File newsDir = new File(endPath);
if (!newsDir.exists()) {
newsDir.mkdirs();
//文件存在就删除//
if (file.isFile()) {//
file.deleteOnExit();//
file = new File(newFilePath);//
OutputStreamWriter os = null;
if (enc == null || enc.length() == 0) {
os = new OutputStreamWriter(new FileOutputStream(file));
os = new OutputStreamWriter(new FileOutputStream(file), enc);
os.write(content);
os.close();
} catch (Exception e) {
e.printStackTrace();
return false;
return true; }}
HttpClient 4.3.* 上传带中文文件名文件文件名乱码问题的解决 - kcher
最后更新时间
import java.io.Fimport java.io.IOEimport java.nio.charset.Cimport org.apache.http.Cimport org.apache.http.HttpEimport org.apache.http.client.methods.CloseableHttpRimport org.apache.http.client.methods.HttpPimport org.apache.http.entity.ContentTimport org.apache.http.entity.mime.HttpMultipartMimport org.apache.http.entity.mime.MultipartEntityBimport org.apache.http.entity.mime.content.FileBimport org.apache.http.entity.mime.content.StringBimport org.apache.http.impl.client.CloseableHttpCimport org.apache.http.impl.client.HttpCimport org.apache.http.util.CharsetUimport org.apache.http.util.EntityUpublic class FileUploadTest {
* 这个例子展示了如何执行请求包含一个多部分编码的实体 模拟表单提交
* @throws IOException
public static void main(String[] args) throws IOException {
CloseableHttpClient httpClient = HttpClients.createDefault();
// 要上传的文件的路径
String filePath = new String(&D:\\吹风.gif&);
// 把一个普通参数和文件上传给下面这个地址 是一个servlet
HttpPost httpPost = new HttpPost(
&http://localhost:8080/abc/updateUserBgImg&);
// 把文件转换成流对象FileBody
File file = new File(filePath);
FileBody bin = new FileBody(file);
StringBody userId = new StringBody(
&用户ID&, ContentType.create(
&text/plain&, Consts.UTF_8));
//以浏览器兼容模式运行,防止文件名乱码。
HttpEntity reqEntity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
.addPart(&multipartFile&, bin)
.addPart(&userId&, userId).setCharset(CharsetUtils.get(&UTF-8&)).build();
httpPost.setEntity(reqEntity);
System.out.println(&发起请求的页面地址 & + httpPost.getRequestLine());
// 发起请求 并返回请求的响应
CloseableHttpResponse response = httpClient.execute(httpPost);
System.out.println(&----------------------------------------&);
// 打印响应状态
System.out.println(response.getStatusLine());
// 获取响应对象
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
// 打印响应长度
System.out.println(&Response content length: &
+ resEntity.getContentLength());
// 打印响应内容
System.out.println(EntityUtils.toString(resEntity,
Charset.forName(&UTF-8&)));
EntityUtils.consume(resEntity);
} finally {
response.close();
} finally {
httpClient.close();
基于httpclient-4.5版本的工具类HttpUtils
最后更新时间
HttpUtils.java
package com.ying.commons.utils;import java.io.IOException;import java.net.URISyntaxException;import java.nio.charset.Charset;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Map.Entry;import org.apache.http.Consts;import org.apache.http.HttpEntity;import org.apache.http.HttpResponse;import org.apache.http.NameValuePair;import org.apache.http.StatusLine;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.HttpResponseException;import org.apache.http.client.ResponseHandler;import org.apache.http.client.config.CookieSpecs;import org.apache.http.client.config.RequestConfig;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpPost;import org.apache.http.client.utils.URLEncodedUtils;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;import org.apache.http.impl.client.HttpClients;import org.apache.http.message.BasicNameValuePair;import org.apache.http.util.EntityUtils;import org.slf4j.Logger;import org.slf4j.LoggerFactory;/** * 发送http请求的工具类.基于httpclient-4.5 *
* @version 4.5 * @author ying */public class HttpUtils { private HttpUtils() { } public static final Charset DEFAULT_CHARSET = Consts.UTF_8; private static Logger logger = LoggerFactory.getLogger(HttpUtils.class); // 请求返回的处理器 private static ResponseHandler&String& responseHandler = new ResponseHandler&String&() {
public String handleResponse(final HttpResponse response) throws IOException {
StatusLine statusLine = response.getStatusLine();
HttpEntity entity = response.getEntity();
if (statusLine.getStatusCode() &= 300) {
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
if (entity == null) {
throw new ClientProtocolException(&Response contains no content&);
String result = EntityUtils.toString(entity, DEFAULT_CHARSET);
if (logger.isDebugEnabled()) {
logger.debug(&http response:& + result);
return result;
} }; // httpClient是线程安全的 private static CloseableHttpClient httpClient; static {
// 定义Request的config,一律设置5秒timeout
RequestConfig requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).setConnectionRequestTimeout(5000)
.setConnectTimeout(5000).setSocketTimeout(5000).build();
// 3次重试
httpClient = HttpClients.custom().setRetryHandler(new DefaultHttpRequestRetryHandler(3, false))
.setDefaultRequestConfig(requestConfig).build(); } /**
* get方式请求数据
* @param uri
请求的url,例如:&http://127.0.0.1:8080/test?name=ying&
*/ public static String httpGet(String uri) {
return httpGet(uri, new ArrayList&NameValuePair&(0)); } /**
* get方式请求数据
* @param uri
请求的url,例如:&http://127.0.0.1:8080/test?name=ying&
* @param params
请求参数。方法内部会对参数做UrlEncode,所以传入的参数不能是已经UrlEncoded的&br&
params的值如果为数组或List,例如k=[v1,v2],则会被解析为:k=v1&k=v2
*/ public static String httpGet(String uri, Map&String, Object& params) {
return httpGet(uri, parseParameters(params)); } /**
* post方式请求数据
* @param uri
请求的url,例如:&http://127.0.0.1:8080/test?name=ying&
* @param params
请求参数。方法内部会对参数做UrlEncode,所以传入的参数不能是已经UrlEncoded的&br&
params的值如果为数组或List,例如k=[v1,v2],则会被解析为:k=v1&k=v2
*/ public static String httpPost(String uri, Map&String, Object& params) {
return httpPost(uri, parseParameters(params)); } /**
* get方式请求数据
* @param uri
请求的url,例如:&http://127.0.0.1:8080/test?name=ying&
* @param params
请求参数。方法内部会对参数做UrlEncode,所以传入的参数不能是已经UrlEncoded的
*/ public static String httpGet(String uri, List&NameValuePair& params) {
String url = uri;
if (params != null && params.size() & 0) {
String paramStr = URLEncodedUtils.format(params, DEFAULT_CHARSET);
if (uri.indexOf(&?&) &= 0) {
url += &&&;
url += &?&;
url += paramStr;
HttpGet httpGet = new HttpGet(url);
if (logger.isDebugEnabled()) {
logger.debug(&http get:& + httpGet.getURI());
return httpClient.execute(httpGet, responseHandler);
} catch (ClientProtocolException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
* post方式请求数据
* @param uri
请求的url,例如:&http://127.0.0.1:8080/test?name=ying&
* @param params
请求参数。方法内部会对参数做UrlEncode,所以传入的参数不能是已经UrlEncoded的
*/ public static String httpPost(String uri, List&NameValuePair& params) {
HttpPost httpPost = new HttpPost(uri);
if (params != null && params.size() & 0) {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, DEFAULT_CHARSET);
httpPost.setEntity(entity);
if (logger.isDebugEnabled()) {
logger.debug(&http post:& + httpPost.getURI());
return httpClient.execute(httpPost, responseHandler);
} catch (ClientProtocolException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} } @SuppressWarnings(&unchecked&) public static List&NameValuePair& parseParameters(Map&String, Object& params) {
List&NameValuePair& pairList = new ArrayList&NameValuePair&();
for (Entry&String, Object& entry : params.entrySet()) {
Object value = entry.getValue();
if (value == null) {
value = &&;
if (value.getClass().isArray() || value instanceof List&?&) {
List&Object& listValue = null;
if (value.getClass().isArray()) {
listValue = Arrays.asList((Object[]) value);
} else if (value instanceof List&?&) {
listValue = (List&Object&) value;
for (Object v : listValue) {
if (v == null) {
value = &&;
pairList.add(new BasicNameValuePair(entry.getKey(), v.toString()));
pairList.add(new BasicNameValuePair(entry.getKey(), value.toString()));
return pairList; } public static void main(String[] args) throws URISyntaxException {
String uri = &http://10.25.10.50/v3/gw?method=user.mail.get&;
Map&String, Object& params = new HashMap&String, Object&();
params.put(&appKey&, &7e5d24&);
params.put(&user&, &4030105&);
params.put(&x&, new String[] { &1&, &2& });
System.out.println(httpGet(uri, params));
System.out.println(httpPost(uri, params)); }}
来自CSDN博客:使用httpclient提交数据
最后更新时间
blog__2401252
package com.itheima.qqlogin;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import com.itheima.htmlview.utils.StreamTools;
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private EditText et_name;
private EditText et_pwd;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_name = (EditText) findViewById(R.id.et_name);
et_pwd = (EditText) findViewById(R.id.et_pwd);
public void login(View view){
final String name = et_qq.getText().toString().trim();
final String pwd = et_pwd.getText().toString().trim();
if(TextUtils.isEmpty(name) || TextUtils.isEmpty(pwd)){
Toast.makeText(this, &qq和密码不能空&, 0).show();
new Thread(){
public void run() {
String path = &http://192.168.22.136:8080/web/servlet/LoginServlet?username=&+URLEncoder.encode(name,&UTF-8&)+&&password=&+URLEncoder.encode(pwd,&UTF-8&); //
1、创建一个浏览器:
HttpClient client = new DefaultHttpClient(); //
2、输入一个网址:
HttpGet httpGet = new HttpGet(path); // //
HttpResponse response = client.execute(httpGet);
//获取服务器端返回的响应码(状态码)
int code =
response.getStatusLine().getStatusCode(); //
int code = conn.getResponseCode();
if(code == 200){ //
(2)解析服务器返回的二进制数据,解析成一个字符串 //
InputStream is = conn.getInputStream();
//获取服务器返回的二进制数据流
InputStream is = response.getEntity().getContent();
String result = StreamTools.readStream(is);
System.out.println(&---------&+ result);
} catch (Exception e) {
e.printStackTrace();
}.start();
来自CSDN博客:HttpClient4.4 进行Http连接通讯
最后更新时间
blog__2964921
GET /link?url=chDeV_MryviuBdyQlKlkh0KwL0T4zzEU2jxSeOz2yD8ZPthCpAgRRufNz_4IKFP0AYKVcMkt2fLCmDsQ5a6m6p0PN1IcRz7KIN4R0ONTMrN97rr2JaH0bnFMD-M3Q1eX7W4b-5o-t96AIbNBOP_X05rXjAuw8bX-uNf_I3jPXAe HTTP/1.1Host: User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:38.0) Gecko/ Firefox/38.0Accept: text/html,application/xhtml+xml,application/q=0.9,*/*;q=0.8Accept-Language: zh-CN,q=0.8,en-US;q=0.5,q=0.3Accept-Encoding: gzip, deflateDNT: 1Referer: /link?url=chDeV_MryviuBdyQlKlkh0KwL0T4zzEU2jxSeOz2yD8ZPthCpAgRRufNz_4IKFP0AYKVcMkt2fLCmDsQ5a6m6p0PN1IcRz7KIN4R0ONTMrN97rr2JaH0bnFMD-M3Q1eX7W4b-5o-t96AIbNBOP_X05rXjAuw8bX-uNf_I3jPXAe&wd=&eqid=9adadbea3a9Cookie: bdshare_firstime=2; BIDUPSID=06ACBFD888B048E65E5EE3B6B3409EC8; BDUSS=XZtbDJ5eUZrcjNJTn5oTlF4dHFQQnVHbkt0TUJxZ1YwcEd4QndweW5KVWpsRzVWQVFBQUFBJCQAAAAAAAAAAAEAAACyEbBHem91cWYyMDA3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACMHR1UjB0dVa; ATS_PASS=9; locale= BAIDUID=F3A2EE0D70C7D935C8A2FD:FG=1; BDRCVFR[gltLrB7qNCt]=mk3SLVN4HKm; re__f=%20; BDRCVFR[2hu4KsUxzef]=mk3SLVN4HKm; BDRCVFR[i7zL5H8GeBs]=mk3SLVN4HKm; BDRCVFR[EJVTmGcXpQm]=mk3SLVN4HKm; H_PS_PSSID=________Connection: keep-alive
来自CSDN博客:Android端通过HttpURLConnection上传文件到服务器
最后更新时间
blog__424882
@RequestMapping(value = &/uploadMyImage/{token}&, method = RequestMethod.POST)public @ResponseBody String getUploadFile(HttpServletRequest request, HttpServletResponse response,
@PathVariable String token) { logger.info(&spring3 MVC upload file with Multipart form&); logger.info(&servlet context path : & + request.getSession().getServletContext().getRealPath(&/&)); UserDto profileDto = userService.getUserByToken(token); String imgUUID = &&; try {
if (request instanceof MultipartHttpServletRequest && profileDto.getToken() != null) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
logger.info(&spring3 MVC upload file with Multipart form&);
// does not work, oh my god!!
MultipartFile file = multipartRequest.getFiles(&myfile&).get(0);
InputStream input = file.getInputStream();
long fileSize = file.getSize();
BufferedImage image = ImageIO.read(input);
// create data transfer object
ImageDto dto = new ImageDto();
dto.setCreateDate(new Date());
dto.setFileName(file.getOriginalFilename());
dto.setImage(image);
dto.setCreator(profileDto.getUserName());
dto.setFileSize(fileSize);
dto.setType(ImageAttachmentType.CLIENT_TYPE.getTitle());
dto.setUuid(UUID.randomUUID().toString());
/// save to DB
imgUUID = imageService.createImage(dto);
input.close();
} } catch (Exception e) {
e.printStackTrace();
logger.error(&upload image error&, e); } return imgUUID;}
来自CSDN博客:HttpClient(4.3.5)请求数据,支持https
最后更新时间
blog__371515
package cn.cq.shenyun;import java.io.IOException;import java.io.UnsupportedEncodingException;import java.net.URLEncoder;import java.security.KeyManagementException;import java.security.KeyStore;import java.security.KeyStoreException;import java.security.NoSuchAlgorithmException;import java.security.cert.CertificateException;import java.security.cert.X509Certificate;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Map.Entry;import org.apache.http.*;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.HttpClient;import org.apache.http.client.config.RequestConfig;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.*;import org.apache.http.config.ConnectionConfig;import org.apache.http.config.Registry;import org.apache.http.config.RegistryBuilder;import org.apache.http.conn.socket.ConnectionSocketFactory;import org.apache.http.conn.socket.LayeredConnectionSocketFactory;import org.apache.http.conn.socket.PlainConnectionSocketFactory;import org.apache.http.conn.ssl.SSLConnectionSocketFactory;import org.apache.http.conn.ssl.SSLContexts;import org.apache.http.conn.ssl.TrustStrategy;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.impl.client.HttpClientBuilder;import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;import org.apache.http.message.BasicNameValuePair;import org.apache.http.params.CoreConnectionPNames;import org.apache.http.util.EntityUtils;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import javax.net.ssl.SSLContext;public class HttpUtilDemo { private static final Logger logger = LoggerFactory.getLogger(HttpUtilDemo.class); private static int SocketTimeout = 3000;//3秒 private static int ConnectTimeout = 3000;//3秒 private static Boolean SetTimeOut = true; private static CloseableHttpClient getHttpClient() {
RegistryBuilder&ConnectionSocketFactory& registryBuilder = RegistryBuilder.&ConnectionSocketFactory&create();
ConnectionSocketFactory plainSF = new PlainConnectionSocketFactory();
registryBuilder.register(&http&, plainSF);//指定信任密钥存储对象和连接套接字工厂
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
//信任任何链接
TrustStrategy anyTrustStrategy = new TrustStrategy() {
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
return true;
SSLContext sslContext = SSLContexts.custom().useTLS().loadTrustMaterial(trustStore, anyTrustStrategy).build();
LayeredConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
registryBuilder.register(&https&, sslSF);
} catch (KeyStoreException e) {
throw new RuntimeException(e);
} catch (KeyManagementException e) {
throw new RuntimeException(e);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
Registry&ConnectionSocketFactory& registry = registryBuilder.build();
//设置连接管理器
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(registry);//
connManager.setDefaultConnectionConfig(connConfig);//
connManager.setDefaultSocketConfig(socketConfig);
//构建客户端
return HttpClientBuilder.create().setConnectionManager(connManager).build(); } /**
* @param url
* @param queries 请求的参数,在浏览器?后面的数据,没有可以传null
* @throws IOException
*/ public static String get(String url, Map&String, String& queries) throws IOException {
String responseBody = &&;
//CloseableHttpClient httpClient=HttpClients.createDefault();
//支持https
CloseableHttpClient httpClient = getHttpClient();
StringBuilder sb = new StringBuilder(url);
if (queries != null && queries.keySet().size() & 0) {
boolean firstFlag = true;
Iterator iterator = queries.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry&String, String&) iterator.next();
if (firstFlag) {
sb.append(&?& + (String) entry.getKey() + &=& + (String) entry.getValue());
firstFlag = false;
sb.append(&&& + (String) entry.getKey() + &=& + (String) entry.getValue());
HttpGet httpGet = new HttpGet(sb.toString());
if (SetTimeOut) {
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(SocketTimeout)
.setConnectTimeout(ConnectTimeout).build();//设置请求和传输超时时间
httpGet.setConfig(requestConfig);
System.out.println(&Executing request & + httpGet.getRequestLine());
//请求数据
CloseableHttpResponse response = httpClient.execute(httpGet);
System.out.println(response.getStatusLine());
int status = response.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
// do something useful with the response body
// and ensure it is fully consumed
responseBody = EntityUtils.toString(entity);
//EntityUtils.consume(entity);
System.out.println(&http return status error:& + status);
throw new ClientProtocolException(&Unexpected response status: & + status);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
httpClient.close();
return responseBody; } /** post
* @param url
* @param queries 请求的参数,在浏览器?后面的数据,没有可以传null
* @param params
post form 提交的参数
* @throws IOException
*/ public static String post(String url, Map&String, String& queries, Map&String, String& params) throws IOException {
String responseBody = &&;
//CloseableHttpClient httpClient = HttpClients.createDefault();
//支持https
CloseableHttpClient httpClient = getHttpClient();
StringBuilder sb = new StringBuilder(url);
if (queries != null && queries.keySet().size() & 0) {
boolean firstFlag = true;
Iterator iterator = queries.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry&String, String&) iterator.next();
if (firstFlag) {
sb.append(&?& + (String) entry.getKey() + &=& + (String) entry.getValue());
firstFlag = false;
sb.append(&&& + (String) entry.getKey() + &=& + (String) entry.getValue());
//指定url,和http方式
HttpPost httpPost = new HttpPost(sb.toString());
if (SetTimeOut) {
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(SocketTimeout)
.setConnectTimeout(ConnectTimeout).build();//设置请求和传输超时时间
httpPost.setConfig(requestConfig);
//添加参数
List&NameValuePair& nvps = new ArrayList&NameValuePair&();
if (params != null && params.keySet().size() & 0) {
Iterator&Map.Entry&String, String&& iterator = params.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry&String, String& entry = (Map.Entry&String, String&) iterator.next();
nvps.add(new BasicNameValuePair((String) entry.getKey(), (String) entry.getValue()));
httpPost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
//请求数据
CloseableHttpResponse response = httpClient.execute(httpPost);
System.out.println(response.getStatusLine());
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
// do something useful with the response body
// and ensure it is fully consumed
responseBody = EntityUtils.toString(entity);
//EntityUtils.consume(entity);
System.out.println(&http return status error:& + response.getStatusLine().getStatusCode());
} catch (Exception e) {
e.printStackTrace();
} finally {
response.close();
return responseBody; }}
来自CSDN博客:httpclient 4.5.1---基础
最后更新时间
blog__8547089
package com.cycore.dbs.common.demo.hc;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.InterruptedIOException;import java.io.Reader;import java.net.URI;import java.net.URISyntaxException;import java.net.UnknownHostException;import java.nio.charset.Charset;import java.util.ArrayList;import java.util.List;import java.util.concurrent.atomic.AtomicInteger;import javax.net.ssl.SSLException;import org.apache.http.Consts;import org.apache.http.Header;import org.apache.http.HeaderElement;import org.apache.http.HeaderElementIterator;import org.apache.http.HeaderIterator;import org.apache.http.HttpEntity;import org.apache.http.HttpEntityEnclosingRequest;import org.apache.http.HttpException;import org.apache.http.HttpHost;import org.apache.http.HttpRequest;import org.apache.http.HttpRequestInterceptor;import org.apache.http.HttpResponse;import org.apache.http.HttpStatus;import org.apache.http.HttpVersion;import org.apache.http.NameValuePair;import org.apache.http.ParseException;import org.apache.http.StatusLine;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.HttpRequestRetryHandler;import org.apache.http.client.HttpResponseException;import org.apache.http.client.ResponseHandler;import org.apache.http.client.config.RequestConfig;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.CloseableHttpResponse;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpPost;import org.apache.http.client.protocol.HttpClientContext;import org.apache.http.client.utils.URIBuilder;import org.apache.http.client.utils.URIUtils;import org.apache.http.conn.ConnectTimeoutException;import org.apache.http.conn.ConnectionKeepAliveStrategy;import org.apache.http.entity.BufferedHttpEntity;import org.apache.http.entity.ContentType;import org.apache.http.entity.FileEntity;import org.apache.http.entity.StringEntity;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;import org.apache.http.impl.client.HttpClients;import org.apache.http.impl.client.LaxRedirectStrategy;import org.apache.http.message.BasicHeaderElementIterator;import org.apache.http.message.BasicHttpResponse;import org.apache.http.message.BasicNameValuePair;import org.apache.http.protocol.BasicHttpContext;import org.apache.http.protocol.HttpContext;import org.apache.http.util.EntityUtils;import com.cycore.dbs.vo.RoleVo;import com.google.gson.Gson;import com.google.gson.GsonBuilder;public class HC_Fundamentals { public static void m1(){
CloseableHttpClient client=HttpClients.createDefault();
URI uri=new URIBuilder()
.setScheme(&http&)
.setHost(&&)
.setPath(&/search&)
.setParameter(&q&, &httpclient&)
.setParameter(&aq&, &f&)
HttpGet httpGet=new HttpGet(uri);
System.out.println(httpGet.getURI());
CloseableHttpResponse response=client.execute(httpGet);
HttpEntity entity=response.getEntity();
if(entity!=null){
InputStream is=entity.getContent();
response.close();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
public static void m2(){
HttpResponse httpResponse=new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, &OK&);
System.out.println(httpResponse.getProtocolVersion());//HTTP/1.1
System.out.println(httpResponse.getStatusLine().getStatusCode());//200
System.out.println(httpResponse.getStatusLine().getReasonPhrase());//OK
System.out.println(httpResponse.getStatusLine().toString());//HTTP/1.1 200 OK }
* header的使用
*/ public static void m3(){
HttpResponse response=new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, &OK&);
response.addHeader(&Set-Cookie&, &c1=a; path=/; domain=localhost&);
response.addHeader(&Set-Cookie&, &c2=b; path=\&/\&; c3=c; domain=\&localhost\&&);
Header firstHeader=response.getFirstHeader(&Set-Cookie&);
System.out.println(firstHeader);
Header lastHeader=response.getLastHeader(&Set-Cookie&);
System.out.println(lastHeader);
Header[] headers=response.getHeaders(&Set-Cookie&);
System.out.println(headers.length);
//获取所有header最有效率的方式
HeaderIterator hi=response.headerIterator(&Set-Cookie&);
while(hi.hasNext()){
System.out.println(hi.next());
//将http消息转换成独立的头部元素
HeaderElementIterator hei=new BasicHeaderElementIterator(
response.headerIterator(&Set-Cookie&));
while(hei.hasNext()){
HeaderElement ele=hei.nextElement();
System.out.println(ele.getName()+& = &+ele.getValue());
NameValuePair[] params=ele.getParameters();
for (int i = 0; i & params.length; i++) {
System.out.println(& &+params[i]);
* StringEntity
* @throws ParseException
* @throws IOException
*/ public static void m4() throws ParseException, IOException{
StringEntity stringEntity=new StringEntity(&important message&, ContentType.create(&text/plain&,&UTF-8&));
System.out.println(stringEntity.getContentType());
System.out.println(stringEntity.getContentLength());
System.out.println(EntityUtils.toString(stringEntity));
System.out.println(EntityUtils.toByteArray(stringEntity).length); }
* 1.关闭和entity内容相关的流 或 2.HttpResponse对象本身,以释放系统资源。
* 前者会通过消费实体内容尝试保持潜在连接,而后者则是立马关闭连接。
* @throws ClientProtocolException
* @throws IOException
*/ public static void m5() throws ClientProtocolException, IOException{
CloseableHttpClient client=HttpClients.createDefault();
HttpGet httpGet=new HttpGet(&http://localhost&);
CloseableHttpResponse response=client.execute(httpGet);
HttpEntity entity=response.getEntity();
if(entity!=null){
InputStream inputStream=entity.getContent();
//do something
} finally{
inputStream.close();//1
} finally{
response.close();//2
* 当响应中一部分内容需要被获取,那么消费剩下的消息内容和保持连接可重用的性能消耗会很高。
* 可以通过关闭response终止内容流,连接将不会被重用,但该连接所拥有的所有层次的资源都得到合理的分配。
* @throws ClientProtocolException
* @throws IOException
*/ public static void m6() throws ClientProtocolException, IOException{
CloseableHttpClient client=HttpClients.createDefault();
HttpGet httpGet=new HttpGet(&http://localhost&);
CloseableHttpResponse response=client.execute(httpGet);
HttpEntity entity=response.getEntity();
if(entity!=null){
InputStream inputStream=entity.getContent();
int byte1=inputStream.read();
int byte2=inputStream.read();
//Do not need the rest
} finally{
response.close();
* 推荐使用 HttpEntity#getContent()方法或HttpEntity#writeTo(OutputStream)方法来消费实体内容。
* 虽然使用EntityUtils的各种静态暴露方法很方便的获取实体内容的字节数组或字符串序列,
* 但是不推荐,除非实体内容来自一个可信任的HTTP服务器且限长可知。
* @throws ClientProtocolException
* @throws IOException
*/ public static void m7() throws ClientProtocolException, IOException{
CloseableHttpClient client=HttpClients.createDefault();
HttpGet httpGet=new HttpGet(&http://localhost&);
CloseableHttpResponse response=client.execute(httpGet);
HttpEntity entity=response.getEntity();
if(entity!=null){
long len=entity.getContentLength();
if(len!=-1 && len&2048){
System.out.println(EntityUtils.toString(entity));//EntityUtils获取字符序列
//Stream content out
} finally{
response.close();
* 在有些情况下可能需要多次读取实体内容,这就需要被缓冲进内存或硬盘中。
* 最简单的办法就是用BufferedHttpEntity类包装最初的entity,这样会把最初的entity读进内存缓冲区。
* @throws ClientProtocolException
* @throws IOException
*/ public static void m8() throws ClientProtocolException, IOException{
CloseableHttpClient client=HttpClients.createDefault();
HttpGet httpGet=new HttpGet(&http://localhost&);
CloseableHttpResponse response=client.execute(httpGet);
HttpEntity entity=response.getEntity();
if(entity!=null){
entity=new BufferedHttpEntity(entity);//缓冲封装
} finally{
response.close();
* hc为大多数共同的数据容器比如string , byte array , input stream和file的提供了若干类。
* 这些类有StringEntity ,
ByteArrayEntity ,
InputStreamEntity , 和
FileEntity 。
* 这些类可以通过POST和PUT方式,与闭合请求相关联高效输出内容。
* 注意: InputStreamEntity只能从潜在数据中读取一次,不可重复读。推荐使用自定义HttpEntity实现类
* 替代使用普通的 InputStreamEntity。FileEntity可以成为一个很高的开端。
*/ public static void m9(){
File file =new File(&somefile.txt&);
FileEntity entity=new FileEntity(file, ContentType.create(&text/plain&, &UTF-8&));
HttpPost httpPost=new HttpPost(&http://localhost/action.do&);
httpPost.setEntity(entity);
* UrlEncodedFormEntity-简化了HTML表单提交的过程,使用URL编码编码参数。
* 编码之后的参数看起来像这样: param1=value1?m2=value2
*/ public static void m10(){
List&NameValuePair& formparams=new ArrayList&NameValuePair&();
formparams.add(new BasicNameValuePair(&param1&, &value1&));
formparams.add(new BasicNameValuePair(&param2&, &value2&));
UrlEncodedFormEntity entity=new UrlEncodedFormEntity(formparams, Consts.UTF_8);
HttpPost httpPost=new HttpPost(&http://localhost/action.do&);
httpPost.setEntity(entity); }
* 在基于被传输的HTTP消息中属性,一般来说会推荐让HttpClient选择最合适的传输编码方式。
* entity.setChunked(true)即可通知HttpClient设置块编码。
* 注意:当使用HTTP协议版本时如HTTP/1.0,将忽略该块编码设置。
*/ public static void m11(){
StringEntity entity=new StringEntity(&important message&,
ContentType.create(&plain/text&, Consts.UTF_8));
entity.setChunked(true);
HttpPost httpPost=new HttpPost(&http://localhost/action.do&);
httpPost.setEntity(entity); }
* ResponseHandler-处理响应,其中有个方法handleResponse方法可以保证连接资源的自动释放,
* 不需要担心连接的管理,不管请求执行成功还是失败.
* @throws ClientProtocolException
* @throws IOException
*/ public static void m12() throws ClientProtocolException, IOException{
CloseableHttpClient client=HttpClients.createDefault();
HttpGet httpGet=new HttpGet(&http://localhost/json&);
ResponseHandler&RoleVo& rh = new ResponseHandler&RoleVo&() {
public RoleVo handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
StatusLine statusLine=response.getStatusLine();
HttpEntity entity=response.getEntity();
if(statusLine.getStatusCode() &= 300){
throw new HttpResponseException(
statusLine.getStatusCode(), statusLine.getReasonPhrase());
if(entity == null){
throw new ClientProtocolException(&Response contains no content&);
Gson gson=new GsonBuilder().create();
ContentType contentType=ContentType.get(entity);
Charset charset=contentType.getCharset();
Reader reader=new InputStreamReader(entity.getContent(), charset);
return gson.fromJson(reader, RoleVo.class);
RoleVo roleVo=client.execute(httpGet, rh); }
* HttpClient接口,仅表示HTTP请求执行的最基础的契约.
* 没有对请求执行强加限制或特殊细节。正是如此,
* 可以让诸如状态处理、认证、和重定向处理独立实现它们自身特征。
*/ public static void m13(){
//定制连接空闲时间管理策略
ConnectionKeepAliveStrategy keepAliveStrategy=new DefaultConnectionKeepAliveStrategy(){
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
long keepAlive = super.getKeepAliveDuration(response, context);
if(keepAlive == -1){
//keep connection alive 5 seconds if a keep-alive value
//has not be explicitly set by the server
keepAlive = 5000;
return keepAlive;
CloseableHttpClient httpClient = HttpClients
.setKeepAliveStrategy(keepAliveStrategy)
.build(); }
* HttpClient线程安全和资源重分配
* 1.HttpClient实现被期望是线程安全的,最好该类的同一个实例可被多个请求执行重用;
* 2.当一个CloseableHttpClient实例不再使用或超出了同其相关的连接管理器范围,需要被关闭。
* @throws IOException
*/ public static void m14() throws IOException{
CloseableHttpClient client=HttpClients.createDefault();
} finally{
client.close();
* HttpContext可能含有任意对象所以在多线程中共享时是不安全的。
* 所以为了保证线程安全,需要每一个执行线程都有自己的上下文。
* 多个请求的会话上下文和状态信息可以在同一个HttpContext实例中自动传播。
* @throws ClientProtocolException
* @throws IOException
*/ public static void m15() throws ClientProtocolException, IOException{
HttpContext context=new BasicHttpContext();
HttpClientContext clientContext=HttpClientContext.adapt(context);//
HttpHost target=clientContext.getTargetHost();//
HttpRequest request=clientContext.getRequest();//
HttpResponse response=clientContext.getResponse();//
RequestConfig config=clientContext.getRequestConfig();
CloseableHttpClient client=HttpClients.createDefault();
RequestConfig requestConfig=RequestConfig
.setSocketTimeout(1000)
.setConnectTimeout(1000)
HttpGet httpGet1=new HttpGet(&http://localhost/1&);
httpGet1.setConfig(requestConfig);
CloseableHttpResponse response1=client.execute(httpGet1, clientContext);
HttpEntity entity1=response1.getEntity();
} finally {
response1.close();
HttpGet httpGet2=new HttpGet(&http://localhost/2&);
httpGet2.setConfig(requestConfig);
CloseableHttpResponse response2=client.execute(httpGet2, clientContext);
HttpEntity entity2=response2.getEntity();
} finally {
response2.close();
* HTTP协议拦截器:是实现HTTP协议一个特性方面的例行程序。
* 1.通常,协议拦截器会被期望作用于进入的消息的一个特殊的头部header或一组相关联的头部,或者用一个特殊的头部或一组相关联的头部填充输出消息。
* 2.协议拦截器可以通过HTTP执行上下文合作共享信息如进程状态。协议拦截器可以利用上下文为一个请求或多个连续请求存储一个进程状态。
* 3.通常拦截器的执行顺序影响不是很大只要他们不依赖于执行上下文的一个特殊状态。如果协议拦截器之间有相关性那么就一定要以一个特殊顺序执行,
* 他们应该以被期望的顺序添加进相同的协议进程序列。
* 4.协议拦截器要以线程安全的方式实现。和servlet类似,协议拦截器不应该使用实例变量,除非对变量的访问是线程同步的。
* @throws ClientProtocolException
* @throws IOException
*/ public static void m16() throws ClientProtocolException, IOException{
CloseableHttpClient httpClient=HttpClients.custom().addInterceptorLast(new HttpRequestInterceptor() {
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
AtomicInteger count = (AtomicInteger) context.getAttribute(&count&);
request.addHeader(&Count&, Integer.toString(count.getAndIncrement()));
}).build();
AtomicInteger count=new AtomicInteger(1);
HttpClientContext localContext=HttpClientContext.create();
localContext.setAttribute(&count&, count);
HttpGet httpGet=new HttpGet(&http://localhost/&);
for (int i = 0; i & 10; i++) {
CloseableHttpResponse response=httpClient.execute(httpGet, localContext);
HttpEntity entity=response.getEntity();
} finally {
response.close();
* HttpRequestRetryHandler-请求重试处理程序,自定义实现可以启用异常回复机制。
* 默认的,HttpClient假定非实体附入的方法如GET和HEAD是幂等的,而实体附入的方法如POST和PUT
* 由于兼容性的原因不是幂等的。幂等方法多次请求执行跟一次请求执行的副作用是一样的。
* 在应用层保证HTTP方法的幂等性可以保证HTTP传输层的安全性。
*/ public static void m17(){
HttpRequestRetryHandler myRetryHandler=new HttpRequestRetryHandler() {
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
if(executionCount &= 5){
//Do not retry if over max retry count
return false;
if(exception instanceof InterruptedIOException){
return false;
if(exception instanceof UnknownHostException){
//Unknown host
return false;
if(exception instanceof ConnectTimeoutException){
//Connection refused
return false;
if(exception instanceof SSLException){
//SSL handshake exception
return false;
HttpClientContext clientContext=new HttpClientContext(context);
HttpRequest request = clientContext.getRequest();
boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
if(idempotent){
//Retry if the request is considered idempotent
//如果请求时幂等的则重试
return true;
return false;
CloseableHttpClient httpclient=HttpClients.custom()
.setRetryHandler(myRetryHandler)
.build(); }
* 重定向处理程序
*/ public static void m18(){
LaxRedirectStrategy redirectStrategy=new LaxRedirectStrategy();
CloseableHttpClient client=HttpClients.custom()
.setRedirectStrategy(redirectStrategy)
.build(); }
* HttpClient经常不得不重写执行进程中的请求消息。每个默认的HTTP/1.0和HTTP/1.1广泛使用相对请求统一资源识别符。
* 同样地,最初的请求可能会被从一个位置多次重定向到另一个位置。使用最初的请求和上下文可以生成最后的绝对的经过解释的绝对的HTTP位置。
* 可以使用工具类方法 URIUtils#resolve去达成以产生最后的请求。该方法包含了来自重定向请求或最初请求的最后片段识别符。
* @throws ClientProtocolException
* @throws IOException
* @throws URISyntaxException
*/ public static void m19() throws ClientProtocolException, IOException, URISyntaxException{
CloseableHttpClient httpClient=HttpClients.createDefault();
HttpClientContext context=HttpClientContext.create();
HttpGet httpGet=new HttpGet(&http://localhost:8080&);
CloseableHttpResponse response=httpClient.execute(httpGet, context);
HttpHost target=context.getTargetHost();
List&URI& redirectLocations=context.getRedirectLocations();
URI location = URIUtils.resolve(httpGet.getURI(), target, redirectLocations);
System.out.println(&Final HTTP location: &+location.toASCIIString());
//Expected to be an absolute URI
} finally {
response.close();
public static void main(String[] args) throws ParseException, IOException {//
来自CSDN博客:使用搜狐Sendcloud的Webapi发送邮件:Jodd和Apache Httpclient
最后更新时间
blog__435582
Map&String, String& queryMap = new HashMap&String, String&();
queryMap.put(&api_user&, API_USER);
queryMap.put(&api_key&, API_KEY);
queryMap.put(&from&, FROM);
queryMap.put(&to&, to);
queryMap.put(&subject&, subject);
queryMap.put(&html&, html.substring(0,html.length()));
HttpResponse response = HttpRequest.post(URL)// .contentType(contentType)
.query(queryMap).send();
String body = response.bodyText();
来自CSDN博客:Android开发之网络通讯详解
最后更新时间
blog__3440313
URL url=new URL(&&);httpUrlConnection = (HttpURLConnection) url.openConnection();

我要回帖

更多关于 公众号 将要访问 的文章

 

随机推荐