JAVA https 图片_Java 如何抓到该 SSL 图片?

3

2015-07-11 21:01:08 +08:00

private static String httpRequest(String url, String requestMethod, String postParameters) {

StringBuilder resultString = new StringBuilder();

HttpURLConnection connection = null;

try {

URL urlGet = new URL(url);

// 真正连接在调用http.connect()时;

connection = (HttpURLConnection) urlGet.openConnection();

// 连接超时

connection.setConnectTimeout(CONNECT_TIMEOUT);

// 读取超时 --服务器响应比较慢,增大时间

connection.setReadTimeout(READ_TIMEOUT);

// 设置Http请求method

connection.setRequestMethod(requestMethod);

connection.setDoOutput(true);

connection.setDoInput(true);

if (postParameters != null && requestMethod.equalsIgnoreCase(HTTP_METHOD_POST)) { // Post时调用

connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

connection.setRequestProperty("Content-Length", "" +

Integer.toString(postParameters.getBytes("UTF-8").length));

// 隐式调用 connection.connect();

OutputStream out = connection.getOutputStream();

out.write(postParameters.getBytes(DEFAULT_CHARSET));

out.flush();

out.close();

}

// 隐式调用 connection.connect();

InputStream in = connection.getInputStream();

BufferedReader read = new BufferedReader(new InputStreamReader(in, DEFAULT_CHARSET));

String valueString;

while ((valueString = read.readLine()) != null) {

resultString.append(valueString);

}

in.close();

} catch (IOException e) {

LOGGER.error("Https请求出错!", e);

} finally {

if (connection != null) {

connection.disconnect();

}

}

return resultString.toString();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值