技术标签: java接口接收图片的方式
textMap,
MapfileMap,String contentType) {
String res = "";
HttpURLConnection conn = null;
// boundary就是request头和上传文件内容的分隔符
String BOUNDARY = "---------------------------123821742118716";
try {
URL url = new URL(urlStr);
conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
conn.setReadTimeout(30000);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("User-Agent",
"Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)");
conn.setRequestProperty("Content-Type",
"multipart/form-data; boundary=" + BOUNDARY);
OutputStream out = new DataOutputStream(conn.getOutputStream());
// text
if (textMap != null) {
StringBuffer strBuf = new StringBuffer();
Iterator iter = textMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
String inputName = (String) entry.getKey();
String inputValue = (String) entry.getValue();
if (inputValue == null) {
continue;
}
strBuf.append("\r\n").append("--").append(BOUNDARY)
.append("\r\n");
strBuf.append("Content-Disposition: form-data; name=\""
+ inputName + "\"\r\n\r\n");
strBuf.append(inputValue);
System.out.println(inputName+","+inputValue);
}
out.write(strBuf.toString().getBytes());
}
// file
if (fileMap != null) {
Iterator iter = fileMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
String inputName = (String) entry.getKey();
String inputValue = (String) entry.getValue();
if (inputValue == null) {
continue;
}
File file = new File(inputValue);
String filename = file.getName();
//没有传入文件类型,同时根据文件获取不到类型,默认采用application/octet-stream
contentType = new MimetypesFileTypeMap().getContentType(file);
//contentType非空采用filename匹配默认的图片类型
if(!"".equals(contentType)){
if (filename.endsWith(".png")) {
contentType = "image/png";
}else if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".jpe")) {
contentType = "image/jpeg";
}else if (filename.endsWith(".gif")) {
contentType = "image/gif";
}else if (filename.endsWith(".ico")) {
contentType = "image/image/x-icon";
}
}
if (contentType == null || "".equals(contentType)) {
contentType = "application/octet-stream";
}
StringBuffer strBuf = new StringBuffer();
strBuf.append("\r\n").append("--").append(BOUNDARY)
.append("\r\n");
strBuf.append("Content-Disposition: form-data; name=\""
+ inputName + "\"; filename=\"" + filename
+ "\"\r\n");
System.out.println(inputName+","+filename);
strBuf.append("Content-Type:" + contentType + "\r\n\r\n");
out.write(strBuf.toString().getBytes());
DataInputStream in = new DataInputStream(
new FileInputStream(file));
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = in.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
}
in.close();
}
}
byte[] endData = ("\r\n--" + BOUNDARY + "--\r\n").getBytes();
out.write(endData);
out.flush();
out.close();
// 读取返回数据
StringBuffer strBuf = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
strBuf.append(line).append("\n");
}
res = strBuf.toString();
reader.close();
reader = null;
} catch (Exception e) {
System.out.println("发送POST请求出错。" + urlStr);
e.printStackTrace();
} finally {
if (conn != null) {
conn.disconnect();
conn = null;
}
}
return res;
}
1.添加JDBC Connection Configuration 2.添加JDBC Request 3、添加查看结果树 4、设置下列参数:Database URL:jdbc:mysql://host:port/db(如jdbc:mysql://localhost:3306/testlinkJDBC Driver class:co
项目目录:util.js:var header //请求头// 封装post请求const post = (url, data, isUrl) => { header = { 'content-type': isUrl ? 'application/x-www-form-urlencoded' : 'application/json ', 'Cookie': wx.getStorageSync("cookieKey") //读取cookie 'toekn
文章目录概念基础语法元字符^ 行的开始$ 行的结束[...](字符组)匹配若干字符- (字符组内元字符)匹配范围^ (字符组内元字符) 非(排除)匹配. 匹配任意字符| 多选结构`\< 和 \>` 单词分界符? 可选项元素+ 重复元字符* 重复元字符{} 限定重复次数() 范围限定符,反向应用范围限定反向引用(配合 \number 使用)\ 转义字符(即 需要将元字符当普通字符时,使...
1》ol标签的改良start type reversed:翻转排序2》datalist标签自动补全的使用3》progress标签的使用:进度条4》meter标签的应用5》details展开收缩标签的使用-子标签summary(自动带有展开收缩的效果)6》mark标签的应用:高亮显示文本7》音频标签audio8》视频标签video补充样式:outline:轮廓同border,但是border占位置...
windows update是现在大多数Windows操作系统都带有的一种自动检查更新工具,用来及时更新补丁和修复漏洞等,可以是我们的电脑体验更好更安全,不过最近有windows7系统用户反映说在Windows Update检查更新的时候,无法搜索到可用的更新,而在检查更新的时候还总是提示80244019错误,这让很多用户不知所措,这是怎么回事呢?下面随win7之家小编一起来看看是如何解决的吧!原...
SCI论文二作对研究生有用吗发布时间:2019-09-17 15:37所属分类:期刊常识sci论文可以由多个作者共同完成,其中一作一般是对论文贡献比较大的,二作相对来说要小一些,那么对于研究生毕业论文来说, SCI论文二作对研究生有sci论文可以由多个作者共同完成,其中一作一般是对论文贡献比较大的,二作相对来说要小一些,那么对于研究生毕业论文来说,SCI论文二作对研究生有用吗?研究生毕业论文对作者...
当前最新的 CentOS 7.5 默认安装的是 Python 2.7.5,并且默认的官方 yum 源中不提供 Python 3 的安装包。这里主要介绍两种在 CentOS 7 中安装 Python 3 的方法。使用 SCL 安装1. 启用 SCLSCL 是一个社区项目,它可以在同一系统上构建,安装和使用多个版本的软件,而不会影响系统默认软件包。yum -y install centos-relea...
Summary of Critical and Exploitable iOS Vulnerabilities in 2016Author:Min (Spark) Zheng, Cererdlong, Eakerqiu @ Team OverSky 0x00 IntroductioniOS security is far more...
Apache Hadoop Learning文章目录Apache Hadoop LearningHDFS简介概念交互流程示意图搭建shell命令学习MapReduce简介工作机制设计举个栗子????yarn简介设计执行流程hive简介概念架构执行流程远程模式搭建hive命令参考文献HDFS简介HDFS称为分布式文件系统(Hadoop Distributed Filesystem),有时也简称为DFS。我们可以用以下几个key描述HDFS:超大文件GB、TB甚至PB级别的数据。流式数据访问
哈哈,搜到了就看一眼吧,没准我们疑惑点一样呢,如果写的不对的地方,欢迎批评指正~一、耳熟能详的三个方法1.dispatchTouchEvent()事件分发处理2.onInterceptTouchEvent()是否拦截事件3.onTouchEvent()具体事件处理方法之间的关系image.png二、源码分析一点点来吧,希望不要太枯燥1.dispatchTouchEvent2603 // Check...
随机数发生器是密码学的一个重要原语。密码学库CryptoPP中提供了一些随机数发生器算法。前面讲述了LC_RNG算法的使用:https://blog.csdn.net/Lunar_Queen/article/details/81542372。今天,讲解一下RandomPool随机数发生器算法的使用。...
打印的效果及控制性虽然不是很好,但是也能勉强使用,应付一般的打印还是 可以的了。代码如下所示: 代码 复制代码 代码如下://调用PrintControl.ExecWB(?,?)实现直接打印和打印预览功能。(直接用系统提供的print()方法打印无法隐藏某些区域) //preview:是否显示预览。null/false:不显示,true:显示 function printP...