|
|
|
@ -1,8 +1,8 @@
|
|
|
|
|
package com.op.common.core.utils.http;
|
|
|
|
|
|
|
|
|
|
import com.op.common.core.constant.Constants;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import javax.net.ssl.*;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.net.*;
|
|
|
|
@ -240,6 +240,47 @@ public class HttpUtils {
|
|
|
|
|
return result.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String sendGetOA(String url, String param) throws UnsupportedEncodingException {
|
|
|
|
|
StringBuilder result = new StringBuilder();
|
|
|
|
|
BufferedReader in = null;
|
|
|
|
|
try {
|
|
|
|
|
String urlNameString = url + "?" + param;
|
|
|
|
|
log.info("sendGet - {}" , urlNameString);
|
|
|
|
|
URL realUrl = new URL(urlNameString);
|
|
|
|
|
URLConnection connection = realUrl.openConnection();
|
|
|
|
|
connection.setRequestProperty("accept" , "*/*");
|
|
|
|
|
connection.setRequestProperty("connection" , "Keep-Alive");
|
|
|
|
|
connection.setRequestProperty("user-agent" , "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
|
|
|
|
connection.setRequestProperty("Accept-Charset", "utf-8");
|
|
|
|
|
connection.setRequestProperty("content-Type", "application/json; charset=GBK");
|
|
|
|
|
connection.connect();
|
|
|
|
|
in = new BufferedReader(new InputStreamReader(connection.getInputStream(),"GBK"));
|
|
|
|
|
String line;
|
|
|
|
|
while ((line = in.readLine()) != null) {
|
|
|
|
|
result.append(line);
|
|
|
|
|
}
|
|
|
|
|
log.info("recv - {}" , result);
|
|
|
|
|
} catch (ConnectException e) {
|
|
|
|
|
log.error("调用HttpUtils.sendGet ConnectException, url=" + url + ",param=" + param, e);
|
|
|
|
|
} catch (SocketTimeoutException e) {
|
|
|
|
|
log.error("调用HttpUtils.sendGet SocketTimeoutException, url=" + url + ",param=" + param, e);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("调用HttpUtils.sendGet IOException, url=" + url + ",param=" + param, e);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("调用HttpsUtil.sendGet Exception, url=" + url + ",param=" + param, e);
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
if (in != null) {
|
|
|
|
|
in.close();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String str = result.toString();
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class TrustAnyTrustManager implements X509TrustManager {
|
|
|
|
|
@Override
|
|
|
|
|
public void checkClientTrusted(X509Certificate[] chain, String authType) {
|
|
|
|
|