http与https请求
2015-07-23 20:42
555 查看
1.http请求
public static String httpGet(String path, String charsetName) throws IOException{String rv = null;
URL url = null;
HttpURLConnection httpConnection = null;
InputStream input = null;
try {
url = new URL(path);
httpConnection = (HttpURLConnection) url.openConnection();
input = httpConnection.getInputStream();
rv = TohoursUtils.inputStream2String(input, charsetName);
} finally {
if(input != null){
input.close();
}
}
return rv;
}
2.https请求
public static String httpsGet(String path, String charsetName) throws IOException{String rv = null;
URL url = null;
HttpsURLConnection httpsConnection = null;
InputStream input = null;
try {
url = new URL(path);
httpsConnection = (HttpsURLConnection) url.openConnection();
input = httpsConnection.getInputStream();
rv = TohoursUtils.inputStream2String(input, charsetName);
} finally {
if(input != null){
input.close();
}
}
return rv;
}
3.http与https请求的调用
public static String httpGet(String path) throws IOException{if(path.indexOf("https")>=0){
return httpsGet(path, "UTF-8");
} else {
return httpGet(path, "UTF-8");
}
}
4.输入流转String
public static String inputStream2String(InputStream in, String charsetName) throws IOException{StringWriter writer = new StringWriter();
IOUtils.copy(in, writer, charsetName);
String theString = writer.toString();
return theString;
}
相关文章推荐
- 深度神经网络DNN的多GPU数据并行框架 及其在语音识别的应用
- android中的加载网络图片
- http关闭连接
- TCP
- 网络图片抓取--web开发批量盗图!!!!!
- 云计算和大数据时代网络技术揭秘(十四)虚拟桌面
- HttpClient
- Win7和Winxp相互共享文件
- TCP的三次握手,四次挥手全过程
- SpringMVC template和HttpClient post提交
- 个人感觉:又是一年网络游戏
- Android网络应用之WI-FI检测
- 网络中常用的9个命令
- ActionResult的本质四:HttpStatusCodeResult & RedirectResult/RedirectToRouteResult
- httpclient向HTTPS发送数据建立SSL连接时的异常
- HttpUtil的小错误
- HTTP长连接与短连接
- cocos-x 3.5 网络发送数据 post
- apache camel jetty http
- apache camel jetty http