package com.fsds.utils;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
public class HttpUtils {
/**
* get
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @return
* @throws Exception
*/
public static HttpResponse doGet(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpGet request = new HttpGet(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
return httpClient.execute(request);
}
/**
* post form
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param bodys
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
Map<String, String> bodys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (bodys != null) {
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
for (String key : bodys.keySet()) {
nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
}
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
request.setEntity(formEntity);
}
return httpClient.execute(request);
}
/**
* Post String
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
String body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (StringUtils.isNotBlank(body)) {
request.setEntity(new StringEntity(body, "utf-8"));
}
return httpClient.execute(request);
}
/**
* Post stream
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
/**
* Put String
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
String body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (StringUtils.isNotBlank(body)) {
request.setEntity(new StringEntity(body, "utf-8"));
}
return httpClient.execute(request);
}
/**
* Put stream
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
/**
* Delete
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @return
* @throws Exception
*/
public static HttpResponse doDelete(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
return httpClient.execute(request);
}
private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
StringBuilder sbUrl = new StringBuilder();
sbUrl.append(host);
if (!StringUtils.isBlank(path)) {
sbUrl.append(path);
}
if (null != querys) {
StringBuilder sbQuery = new StringBuilder();
for (Map.Entry<String, String> query : querys.entrySet()) {
if (0 < sbQuery.length()) {
sbQuery.append("&");
}
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
sbQuery.append(query.getValue());
}
if (!StringUtils.isBlank(query.getKey())) {
sbQuery.append(query.getKey());
if (!StringUtils.isBlank(query.getValue())) {
sbQuery.append("=");
sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
}
}
}
if (0 < sbQuery.leng
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
阿里云表格识别500次 0元,请自己购买 全网独家,手写程序并测试,完美自用OCR程序,【批量处理OCR】【表格识别】【证件识别】功能都包含 -----【表格识别能够自动导出到电脑生成Excel文件 功能齐全,替换你的阿里服务 key 或者 appcode即可 【需要更改的地方也就是打开程序有错误的地方】都已经用注释标记 【非常醒目】一秒定位去哪里添加key 或者 appcode 两个String字符串修改完了之后,直接运行使用 ExcelOCR(表格识别)中右键直接run, ①本地读取图片的路径默认为 D:pic文件夹,请自己建一个,然后表格图片放进去 ②默认表格图片识别后,excle文件输出到桌面test文件夹,跟图片名一样 IdCardOCR(身份证识别)中直接右键run 身份证识别没有充足时间调试
资源推荐
资源详情
资源评论
收起资源包目录
Aliyun.zip (57个子文件)
Aliyun
.project 382B
src
com
fsds
utils
IdCardOCR.java 5KB
commons-lang3-3.10.jar 511KB
rxjava-2.2.8.jar 2.23MB
aliyun-api-gateway.jar 26KB
httpasyncclient-4.1.4.jar 176KB
slf4j-api-1.7.25.jar 40KB
commons-codec-1.10.jar 278KB
httpcore5-reactive-5.0.1.jar 21KB
httpclient-cache-4.5.6.jar 158KB
FindPNG.java 976B
httpcore5-h2-5.0.1.jar 223KB
httpclient5-5.0.1.jar 761KB
httpcore5-5.0.1.jar 801KB
HttpUtils.java 9KB
httpcore5-testing-5.0.1.jar 144KB
reactive-streams-1.0.2.jar 2KB
httpasyncclient-cache-4.1.4.jar 34KB
httpcore-nio-4.4.10.jar 357KB
fastjson-1.2.72.jar 637KB
Base64.java 8KB
commons-cli-1.4.jar 53KB
json-lib-2.4-jdk15.jar 155KB
httpclient-4.5.6.jar 749KB
ExcelOCR.java 7KB
httpcore-4.4.10.jar 319KB
commons-logging-1.2.jar 60KB
.settings
org.eclipse.jdt.core.prefs 781B
org.eclipse.core.resources.prefs 57B
.classpath 2KB
bin
com
fsds
utils
HttpUtils.class 10KB
commons-lang3-3.10.jar 511KB
HttpUtils$1.class 941B
rxjava-2.2.8.jar 2.23MB
aliyun-api-gateway.jar 26KB
httpasyncclient-4.1.4.jar 176KB
slf4j-api-1.7.25.jar 40KB
commons-codec-1.10.jar 278KB
Base64.class 4KB
httpcore5-reactive-5.0.1.jar 21KB
httpclient-cache-4.5.6.jar 158KB
httpcore5-h2-5.0.1.jar 223KB
httpclient5-5.0.1.jar 761KB
httpcore5-5.0.1.jar 801KB
httpcore5-testing-5.0.1.jar 144KB
reactive-streams-1.0.2.jar 2KB
httpasyncclient-cache-4.1.4.jar 34KB
httpcore-nio-4.4.10.jar 357KB
fastjson-1.2.72.jar 637KB
commons-cli-1.4.jar 53KB
json-lib-2.4-jdk15.jar 155KB
ExcelOCR.class 811B
httpclient-4.5.6.jar 749KB
IdCardOCR.class 1KB
httpcore-4.4.10.jar 319KB
commons-logging-1.2.jar 60KB
FindPNG.class 1KB
共 57 条
- 1
资源评论
- saladcaviar2020-12-11怎么用不了?
义之源源
- 粉丝: 3
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功