https 协议下服务器根据网络地址下载上传文件遇到(PKIX:unable to find valid certification path to requested target 的问题)

使用httpclient  所有站点全部信任 不做身份鉴定:

 public static CloseableHttpClient getHttpClient() throws Exception {
SSLConnectionSocketFactory sslsf = null;
PoolingHttpClientConnectionManager cm = null;
SSLContextBuilder builder = null;
builder = new SSLContextBuilder();
// 全部信任 不做身份鉴定
builder.loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
return true;
}
});
sslsf = new SSLConnectionSocketFactory(builder.build(), new String[]{"SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.2"}, null, NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(sslsf)
.setConnectionManager(cm)
.setConnectionManagerShared(true)
.build();
return httpClient;
}

上传文件:

 public static void postParams(String filepath) {
String url = "http://192.188.188.190:8080/dcs.web/upload";//
CloseableHttpClient httpclient = null;
try {
httpclient = getHttpClient();
}catch (Exception e){
e.printStackTrace();
}
CloseableHttpResponse response = null;
String result = null;
try {
HttpPost httpPost = new HttpPost(url+"upload");
MultipartEntityBuilder mEntityBuilder = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
mEntityBuilder.setCharset(Charset.forName(HttpUtil.ENC_UTF_8));
FileBody file = new FileBody(new File(filepath));
mEntityBuilder.addPart("file", file);
StringBody comment = new StringBody(type, ContentType.APPLICATION_JSON);
mEntityBuilder.addPart("convertType", comment);
HttpEntity reqEntity = mEntityBuilder.build();
httpPost.setEntity(reqEntity);
response = httpclient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
HttpEntity resEntity = response.getEntity();
result = EntityUtils.toString(resEntity);
EntityUtils.consume(resEntity);
JSONObject resultJson = JSONObject.fromObject(result);
//返回是否成功等信息
} else {
exeResultEntity.message = "转换pdf服务无响应!";
}
} catch (Exception e) {
exeResultEntity.message = "pdf转换异常,错误信息:" + e.getMessage();
logger.error("请求DCS转化pdf服务错误!", e);
} finally {
HttpClientUtils.closeQuietly(httpclient);
HttpClientUtils.closeQuietly(response);
}
return exeResultEntity;
}

下载文件:

 public static byte[] downloadFileFromNet(String url){
try {
HttpGet httpget = new HttpGet(url);
HttpClient httpClient = getHttpClient();
HttpResponse response = httpClient.execute(httpget);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
byte[] fileByte = readInputStream(is);
is.close();
return fileByte;
}
}catch (Exception e){
e.printStackTrace();
}
return null;
}

https 协议下服务器根据网络地址下载上传文件问题的更多相关文章

  1. git下载/上传文件提示:git did not exit cleanly

    问题:git操作下载/上传文件,提示信息如下 TortoiseGit-git did not exit cleanly (exit code 1) TortoiseGit-git did not ex ...

  2. 从Linux服务器下载上传文件

    首先要确定好哪两种的连接:Linux常用的有centors和unbantu两种版本,PC端Mac和Windows 如果在两个Linux之间传输,或Linux和Mac之间传输可以使用scp命令,类似于s ...

  3. Android 利用an框架快速实现网络请求(含下载上传文件)

    作者:Bgwan链接:https://zhuanlan.zhihu.com/p/22573081来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. an框架的网络框架是完全 ...

  4. Android上传图片到PHP服务器并且支持浏览器上传文件(word、图片、音乐等)

    暑假已经过了一半了,这才完成计划当中的第二个任务.虽然进度是慢了点.但也算是暑假的收获吧.下面我就把我学习当中的收获记录在此. 还是跟以往一样,先上图片. 操作的步骤:打开程序---->选择上传 ...

  5. windows下sublime通过sftp扩展上传文件到linux服务器上

    首先在package controll下载sftp扩展,在任意磁盘下新建文件夹: 然后,添加该文件夹到sublime中,并在xhell中链接linux服务器,新建目录,mkdir  /home/hel ...

  6. 亚马逊S3下载上传文件

    引用网址: http://www.jxtobo.com/27697.html 下载 CloudBerry Explorer http://www.cloudberrylab.com/download- ...

  7. phpstorm连接服务器,实时编辑上传文件到服务器

    教程一:我的老版本,并且是汉化的,找到该位置 打开后:点击Configuration进行配置! 输入服务器的ip.端口.用户名.密码即可 打开编辑: 教程二:下面更新了一个新版本的(2018.2): ...

  8. root账号无法上传文件到Linux服务器

    普通权限的账号,通过ftp工具,可以正常连上Linux服务器,可以正常上传文件.但是root账号却无法上传文件. 网上搜了半天才知道,默认情况下vsftp是不允许root用户登录的,可以通过修改限制来 ...

  9. Dubbo服务 上传文件解决方案以及Hessian协议

    ​ 协议支持 Dubbo支持多种协议,如下所示: Dubbo协议 Hessian协议 HTTP协议 RMI协议 WebService协议 Thrift协议 Memcached协议 Redis协议 在通 ...

随机推荐

  1. Experience of Python Learning Week 1

    1.The founder of python is Guido van Rossum ,he created it on Christmas in 1989, smriti of ABC langu ...

  2. POI读取excel工具类 返回实体bean集合(xls,xlsx通用)

    本文举个简单的实例 读取上图的 excel文件到 List<User>集合 首先 导入POi 相关 jar包 在pom.xml 加入 <!-- poi --> <depe ...

  3. node 简介 起源

    最近的node 的一篇文章阅读量很大,所以写一篇基础篇供大家分享,抛砖引玉,各取所需. 部分内容来源大神笔记. Node.js 简介:@@@@@@@@@@@@@@@@@@@ Node.js是目前非常火 ...

  4. Eclipse详细设置护眼背景色和字体颜色并导出

    Eclipse详细设置护眼背景色和字体颜色并导出 Eclipse是一款码农们喜闻乐见的集成开发平台,但是其默认的主题和惨白的背景色实在是太刺激眼球了.下面,将给大家详细介绍如何设置成护眼主题的方法,也 ...

  5. 时间标签DateTime

    1:DateTime类型初始化: DateTime date=new DateTime(2017,01,19,18,23,00);//此内部对应年,月,日,时,分,秒 Console.WriteLin ...

  6. Nlpir Parser灵玖文本语义挖掘系统数据采集

    在计算机广泛应用的今天,数据采集的重要性是十分显著的.它是计算机与外部物理世界连接的桥梁.各种类型信号采集的难易程度差别很大. 灵玖软件Nlpir Parser文本语义挖掘系统以分词技术为基础,集成了 ...

  7. Thread(线程)四

    今天继续讲讲线程的异常处理.线程取消.多线程的临时变量和线程安全lock的问题. 1.异步处理. 一般来说如果是同步方法的异步处理,我们大多都是try catch住,但是异步方法应该怎么做呢. #re ...

  8. 16. leetcode 404. Sum of Left Leaves

    Find the sum of all left leaves in a given binary tree. Example:     3    / \   9  20     /  \    15 ...

  9. 机器学习实战 logistic回归 python代码

    # -*- coding: utf-8 -*- """ Created on Sun Aug 06 15:57:18 2017 @author: mdz "&q ...

  10. C#生成无重复的随机数

    大一学期末的时候做课程设计时遇到过生成无重复随机数的问题,今天自己也写出来了: static int[] Create_Value() { Random ran = new Random(); //生 ...