|
|
@@ -194,40 +194,40 @@ public class HttpClientUtil {
|
|
|
public static String httpRequest(String requestUrl,String method,String param , Map<String ,String> header){
|
|
|
StringBuffer buffer=null;
|
|
|
try{
|
|
|
-// TrustManager[] tm={new MyX509TrustManager()};
|
|
|
-// //初始化
|
|
|
-// URL url=new URL(requestUrl);
|
|
|
-// sun.net.www.protocol.http.HttpURLConnection conn = (sun.net.www.protocol.http.HttpURLConnection) url.openConnection();
|
|
|
-//// HttpsURLConnection conn=(HttpsURLConnection)url.openConnection();
|
|
|
-// conn.setDoOutput(true);
|
|
|
-// conn.setDoInput(true);
|
|
|
-// conn.setUseCaches(false);
|
|
|
-// conn.setRequestMethod(method);
|
|
|
-// if(null != header && !header.isEmpty()){
|
|
|
-// Set set = header.keySet();
|
|
|
-// Iterator<String> iterator = set.iterator();
|
|
|
-// while (iterator.hasNext()){
|
|
|
-// String key = iterator.next();
|
|
|
-// conn.setRequestProperty(key, header.get(key));
|
|
|
-// }
|
|
|
-// }
|
|
|
-// conn.connect();
|
|
|
-// //往服务器端写内容
|
|
|
-// if(null!=param){
|
|
|
-// OutputStream os=conn.getOutputStream();
|
|
|
-// os.write(param.getBytes("utf-8"));
|
|
|
-// os.close();
|
|
|
-// }
|
|
|
-// log.debug("http请求code:{},msg:{}", conn.getResponseCode(), conn.getResponseMessage());
|
|
|
-// //读取服务器端返回的内容
|
|
|
-// InputStream is=conn.getInputStream();
|
|
|
-// InputStreamReader isr=new InputStreamReader(is,"utf-8");
|
|
|
-// BufferedReader br=new BufferedReader(isr);
|
|
|
-// buffer=new StringBuffer();
|
|
|
-// String line=null;
|
|
|
-// while((line=br.readLine())!=null){
|
|
|
-// buffer.append(line);
|
|
|
-// }
|
|
|
+ TrustManager[] tm={new MyX509TrustManager()};
|
|
|
+ //初始化
|
|
|
+ URL url=new URL(requestUrl);
|
|
|
+ sun.net.www.protocol.http.HttpURLConnection conn = (sun.net.www.protocol.http.HttpURLConnection) url.openConnection();
|
|
|
+// HttpsURLConnection conn=(HttpsURLConnection)url.openConnection();
|
|
|
+ conn.setDoOutput(true);
|
|
|
+ conn.setDoInput(true);
|
|
|
+ conn.setUseCaches(false);
|
|
|
+ conn.setRequestMethod(method);
|
|
|
+ if(null != header && !header.isEmpty()){
|
|
|
+ Set set = header.keySet();
|
|
|
+ Iterator<String> iterator = set.iterator();
|
|
|
+ while (iterator.hasNext()){
|
|
|
+ String key = iterator.next();
|
|
|
+ conn.setRequestProperty(key, header.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conn.connect();
|
|
|
+ //往服务器端写内容
|
|
|
+ if(null!=param){
|
|
|
+ OutputStream os=conn.getOutputStream();
|
|
|
+ os.write(param.getBytes("utf-8"));
|
|
|
+ os.close();
|
|
|
+ }
|
|
|
+ log.debug("http请求code:{},msg:{}", conn.getResponseCode(), conn.getResponseMessage());
|
|
|
+ //读取服务器端返回的内容
|
|
|
+ InputStream is=conn.getInputStream();
|
|
|
+ InputStreamReader isr=new InputStreamReader(is,"utf-8");
|
|
|
+ BufferedReader br=new BufferedReader(isr);
|
|
|
+ buffer=new StringBuffer();
|
|
|
+ String line=null;
|
|
|
+ while((line=br.readLine())!=null){
|
|
|
+ buffer.append(line);
|
|
|
+ }
|
|
|
}catch(Exception e){
|
|
|
log.error("http请求失败:{}",e);
|
|
|
}
|