|
@@ -1,117 +0,0 @@
|
|
-//package com.qmth.teachcloud.cas.util.bjwlxy;
|
|
|
|
-//
|
|
|
|
-//import org.apache.commons.httpclient.*;
|
|
|
|
-//import org.apache.commons.httpclient.methods.PostMethod;
|
|
|
|
-//
|
|
|
|
-//import java.io.BufferedReader;
|
|
|
|
-//import java.io.IOException;
|
|
|
|
-//import java.io.InputStreamReader;
|
|
|
|
-//import java.io.UnsupportedEncodingException;
|
|
|
|
-//import java.util.Map;
|
|
|
|
-//
|
|
|
|
-//public class ResponseWithHttpClient {
|
|
|
|
-// private static MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
|
|
|
|
-//
|
|
|
|
-// private static int connectionTimeOut = 20000;
|
|
|
|
-//
|
|
|
|
-// private static int socketTimeOut = 10000;
|
|
|
|
-//
|
|
|
|
-// private static int MaxtotalConnections = 40;
|
|
|
|
-//
|
|
|
|
-// private static int MaxConnectionsPerHost = 35;
|
|
|
|
-//
|
|
|
|
-// private static boolean mark = false;
|
|
|
|
-//
|
|
|
|
-// public static void SetPara() {
|
|
|
|
-// manager.getParams().setConnectionTimeout(connectionTimeOut);
|
|
|
|
-// manager.getParams().setSoTimeout(socketTimeOut);
|
|
|
|
-// manager.getParams().setDefaultMaxConnectionsPerHost(MaxConnectionsPerHost);
|
|
|
|
-// manager.getParams().setMaxTotalConnections(MaxtotalConnections);
|
|
|
|
-// mark = true;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// public static String getResponseWithHttpClient(String url, String encode) {
|
|
|
|
-// HttpClient client = new HttpClient((HttpConnectionManager) manager);
|
|
|
|
-// if (mark) {
|
|
|
|
-// SetPara();
|
|
|
|
-// }
|
|
|
|
-// PostMethod postMethod = new PostMethod(url);
|
|
|
|
-// postMethod.getParams().setParameter("http.protocol.content-charset", encode);
|
|
|
|
-// String result = null;
|
|
|
|
-// StringBuffer buffer = new StringBuffer();
|
|
|
|
-// BufferedReader reader = null;
|
|
|
|
-// try {
|
|
|
|
-// client.executeMethod((HttpMethod) postMethod);
|
|
|
|
-// reader = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream(), postMethod.getResponseCharSet()));
|
|
|
|
-// String inputLine = null;
|
|
|
|
-// while ((inputLine = reader.readLine()) != null) {
|
|
|
|
-// buffer.append(inputLine);
|
|
|
|
-// }
|
|
|
|
-// result = buffer.toString();
|
|
|
|
-// result = ConverterStringCode(buffer.toString(), postMethod.getResponseCharSet(), encode);
|
|
|
|
-// } catch (Exception e) {
|
|
|
|
-// e.printStackTrace();
|
|
|
|
-// result = "";
|
|
|
|
-// } finally {
|
|
|
|
-// }
|
|
|
|
-// try {
|
|
|
|
-// postMethod.releaseConnection();
|
|
|
|
-// reader.close();
|
|
|
|
-// } catch (IOException iOException) {
|
|
|
|
-// }
|
|
|
|
-// return result;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// public static String getResponseWithHttpClient(String url, String encode, Map<String, String> content) {
|
|
|
|
-// HttpClient client = new HttpClient((HttpConnectionManager) manager);
|
|
|
|
-// if (mark) {
|
|
|
|
-// SetPara();
|
|
|
|
-// }
|
|
|
|
-// PostMethod postMethod = new PostMethod(url);
|
|
|
|
-// if (content != null && content.size() > 0) {
|
|
|
|
-// int index = 0;
|
|
|
|
-// NameValuePair[] nvArray = new NameValuePair[content.size()];
|
|
|
|
-// for (Map.Entry<String, String> entry : content.entrySet()) {
|
|
|
|
-// nvArray[index] = new NameValuePair(entry.getKey(), entry.getValue());
|
|
|
|
-// index++;
|
|
|
|
-// }
|
|
|
|
-// postMethod.setRequestBody(nvArray);
|
|
|
|
-// }
|
|
|
|
-// postMethod.getParams().setParameter("http.protocol.content-charset", encode);
|
|
|
|
-// String result = null;
|
|
|
|
-// StringBuffer buffer = new StringBuffer();
|
|
|
|
-// BufferedReader reader = null;
|
|
|
|
-// try {
|
|
|
|
-// client.executeMethod((HttpMethod) postMethod);
|
|
|
|
-// reader = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream(), postMethod.getResponseCharSet()));
|
|
|
|
-// String inputLine = null;
|
|
|
|
-// while ((inputLine = reader.readLine()) != null) {
|
|
|
|
-// buffer.append(inputLine);
|
|
|
|
-// }
|
|
|
|
-// result = buffer.toString();
|
|
|
|
-// result = ConverterStringCode(buffer.toString(), postMethod.getResponseCharSet(), encode);
|
|
|
|
-// } catch (Exception e) {
|
|
|
|
-// e.printStackTrace();
|
|
|
|
-// result = "";
|
|
|
|
-// } finally {
|
|
|
|
-// }
|
|
|
|
-// try {
|
|
|
|
-// postMethod.releaseConnection();
|
|
|
|
-// reader.close();
|
|
|
|
-// } catch (IOException iOException) {
|
|
|
|
-// }
|
|
|
|
-// return result;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// private static String ConverterStringCode(String source, String srcEncode, String destEncode) {
|
|
|
|
-// if (source != null) {
|
|
|
|
-// try {
|
|
|
|
-// return new String(source.getBytes(srcEncode), destEncode);
|
|
|
|
-// } catch (UnsupportedEncodingException e) {
|
|
|
|
-// e.printStackTrace();
|
|
|
|
-// return "";
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// return "";
|
|
|
|
-// }
|
|
|
|
-//}
|
|
|