https 协议下服务器根据网络地址下载上传文件问题
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 协议下服务器根据网络地址下载上传文件问题的更多相关文章
- git下载/上传文件提示:git did not exit cleanly
问题:git操作下载/上传文件,提示信息如下 TortoiseGit-git did not exit cleanly (exit code 1) TortoiseGit-git did not ex ...
- 从Linux服务器下载上传文件
首先要确定好哪两种的连接:Linux常用的有centors和unbantu两种版本,PC端Mac和Windows 如果在两个Linux之间传输,或Linux和Mac之间传输可以使用scp命令,类似于s ...
- Android 利用an框架快速实现网络请求(含下载上传文件)
作者:Bgwan链接:https://zhuanlan.zhihu.com/p/22573081来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. an框架的网络框架是完全 ...
- Android上传图片到PHP服务器并且支持浏览器上传文件(word、图片、音乐等)
暑假已经过了一半了,这才完成计划当中的第二个任务.虽然进度是慢了点.但也算是暑假的收获吧.下面我就把我学习当中的收获记录在此. 还是跟以往一样,先上图片. 操作的步骤:打开程序---->选择上传 ...
- windows下sublime通过sftp扩展上传文件到linux服务器上
首先在package controll下载sftp扩展,在任意磁盘下新建文件夹: 然后,添加该文件夹到sublime中,并在xhell中链接linux服务器,新建目录,mkdir /home/hel ...
- 亚马逊S3下载上传文件
引用网址: http://www.jxtobo.com/27697.html 下载 CloudBerry Explorer http://www.cloudberrylab.com/download- ...
- phpstorm连接服务器,实时编辑上传文件到服务器
教程一:我的老版本,并且是汉化的,找到该位置 打开后:点击Configuration进行配置! 输入服务器的ip.端口.用户名.密码即可 打开编辑: 教程二:下面更新了一个新版本的(2018.2): ...
- root账号无法上传文件到Linux服务器
普通权限的账号,通过ftp工具,可以正常连上Linux服务器,可以正常上传文件.但是root账号却无法上传文件. 网上搜了半天才知道,默认情况下vsftp是不允许root用户登录的,可以通过修改限制来 ...
- Dubbo服务 上传文件解决方案以及Hessian协议
协议支持 Dubbo支持多种协议,如下所示: Dubbo协议 Hessian协议 HTTP协议 RMI协议 WebService协议 Thrift协议 Memcached协议 Redis协议 在通 ...
随机推荐
- python 图形界面开发
用python来开发图形界面,确实不是很方便,没有c#,Java,甚至VB来得容易.几个控件拖拽,然后响应事件. 用python写脚本,或者web service来处理一般工作,绰绰有余.但有的时候, ...
- (转)OGNL表达式介绍
OGNL是Object-Graph Navigation Language的缩写,它是一种功能强大的表达式语言(Expression Language,简称为EL),通过它简单一致的表达式语法,可以存 ...
- Objective-C 使用核心动画CAAnimation实现动画
先来看看效果吧 整个核心动画就不多做介绍了,随便一搜就能有很多很详细的解释,主要使用以下四种 CABasicAnimation //经典动画 CAKeyframeAnimation //关键帧动画 C ...
- 关于position
一.position 一)语法: 看了那么久的语法,终于到了讲正题的时间了. 二)定位 1.相对定位:相对元素自己在没有定位之前的位置进行位移,元素仍然保留还没有原来的位置. 特性: 1)不脱离文档流 ...
- ArrayList的实现细节(基于JDK1.8)
ArrayList是我们经常用到的一个类,下面总结一下它内部的实现细节和使用时要注意的地方. 基本概念 ArrayList在数据结构的层面上讲,是一个用数组实现的list,从应用层面上讲,就是一个容量 ...
- 福利 c++ 标准头文件大全
#include<cmath> #include<math.h> #include<ctype.h> #include<algorithm> #incl ...
- JavaScript获取客户端IP地址
1. 第三方接口 1) 这里提供一个搜狐接口的地址:http://pv.sohu.com/cityjson?ie=utf-8 ,将这个js引入到页面即可得到returnCitySN. 2) api.i ...
- NYOJ 25 A Famous Music Composer
A Famous Music Composer 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 Mr. B is a famous music composer. O ...
- 高性能MySQL之【第十五章 备份与恢复】学习记录
我们不打算包括的话题: 安全(访问备份,恢复数据的权限,文件是否需要加密) 备份存储在哪里,包括他们应该离源数据多远,以及如何将数据从源头移动到目的地 保留策略.审计 ...
- 通过反射实现Json数据部分更新JavaBean的属性
工作中遇到一个需求,根据对方返回Json来更新Java对象.查阅资料,写了个工具类,同时学到了反射获取集合泛型类型.代码里json类库为fastjson public class JsonUtil { ...