package com.funtester.httpclient;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.funtester.base.bean.RequestInfo;
import com.funtester.base.exception.ParamException;
import com.funtester.base.exception.RequestException;
import com.funtester.base.interfaces.IBase;
import com.funtester.config.Constant;
import com.funtester.config.HttpClientConstant;
import com.funtester.db.mysql.MySqlTest;
import com.funtester.frame.SourceCode;
import com.funtester.utils.DecodeEncode;
import com.funtester.utils.Regex;
import com.funtester.utils.Time;
import com.funtester.utils.message.AlertOver;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.*;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
/**
* 请求相关类,采用统一的静态方法,在登录后台管理页面是自动化设置cookie,其他公参由各自的base类实现header
*/
public class FunLibrary extends SourceCode {
private static Logger logger = LogManager.getLogger(FunLibrary.class);
/**
* ibase实现类,需要用来校验响应是否正确的响应体,获取响应的code码,code码默认-2,对于不同的项目ibase的isright方法不一样
*/
private static IBase iBase;
/**
* 最近发送的请求
*/
private static HttpRequestBase lastRequest;
/**
* 是否保存请求和响应
*/
public static boolean SAVE_KEY = false;
/**
* 方法已重载,获取get对象
* <p>方法重载,主要区别参数,会自动进行urlencode操作</p>
*
* @param url 表示请求地址
* @param args 表示传入数据
* @return 返回get对象
*/
public static HttpGet getHttpGet(String url, JSONObject args) {
if (args == null || args.size() == 0) return getHttpGet(url);
String uri = url + changeJsonToArguments(args);
return getHttpGet(uri);
}
/**
* 方法已重载,获取get对象
* <p>方法重载,主要区别参数,会自动进行urlencode操作</p>
*
* @param url 表示请求地址
* @return 返回get对象
*/
public static HttpGet getHttpGet(String url) {
return new HttpGet(url.replace(SPACE_1, EMPTY));
}
/**
* 获取post对象,以form表单提交数据
* <p>方法重载,文字信息form表单提交,文件信息二进制流提交,具体参照文件上传的方法主食,post请求可以不需要参数,暂时不支持其他参数类型,如果是公参需要在url里面展示,需要传一个json对象,一般默认args为get公参,params为post请求参数</p>
* 请求header参数类型为{@link HttpClientConstant#ContentType_FORM}
*
* @param url 请求地址
* @param params 请求数据,form表单形式设置请求实体
* @return 返回post对象
*/
public static HttpPost getHttpPost(String url, JSONObject params) {
HttpPost httpPost = getHttpPost(url);
setFormHttpEntity(httpPost, params);
httpPost.addHeader(HttpClientConstant.ContentType_FORM);
return httpPost;
}
/**
* 获取httppost对象,没有参数设置
* <p>方法重载,文字信息form表单提交,文件信息二进制流提交,具体参照文件上传的方法主食,post请求可以不需要参数,暂时不支持其他参数类型,如果是公参需要在url里面展示,需要传一个json对象,一般默认args为get公参,params为post请求参数</p>
*
* @param url
* @return
*/
public static HttpPost getHttpPost(String url) {
return new HttpPost(url.replace(SPACE_1, EMPTY));
}
/**
* 获取httppost对象,json格式对象,传参时手动tostring
* <p>新重载方法,适应post请求json传参,估计utf-8编码格式</p>
* 请求header参数类型为{@link HttpClientConstant#ContentType_JSON}
*
* @param url
* @param params
* @return
*/
public static HttpPost getHttpPost(String url, String params) {
HttpPost httpPost = getHttpPost(url);
httpPost.setEntity(new StringEntity(params, DEFAULT_CHARSET.toString()));
httpPost.addHeader(HttpClientConstant.ContentType_JSON);
return httpPost;
}
/**
* * 获取httppost对象,json格式对象,传参时手动tostring
* <p>新重载方法,适应post请求json传参</p>
* 请求header参数类型为{@link HttpClientConstant#ContentType_JSON}
*
* @param url
* @param args
* @return
*/
public static HttpPost getHttpPost(String url, JSONObject args, String params) {
return getHttpPost(url + changeJsonToArguments(args), params);
}
/**
* 获取 httppost 请求对象
* <p>方法重载,文字信息form表单提交,文件信息二进制流提交,具体参照文件上传的方法主食,post请求可以不需要参数,暂时不支持其他参数类型,如果是公参需要在url里面展示,需要传一个json对象,一般默认args为get公参,params为post请求参数</p>
*
* @param url 请求地址
* @param args 请求地址参数
* @param params 请求参数
* @return
*/
public static HttpPost getHttpPost(String url, JSONObject args, JSONObject params) {
return getHttpPost(url + changeJsonToArguments(args), params);
}
/**
* 获取 httpPost 对象
* <p>方法重载,文字信息form表单提交,文件信息二进制流提交,具体参照文件上传的方法主食,post请求可以不需要参数,暂时不支持其他参数类型,如果是公参需要在url里面展示,需要传一个json对象,一般默认args为get公参,params为post请求参数</p>
*
* @param url 请求地址
* @param args 请求通用参数
* @param params 请求参数,其中二进制流必须是 file
* @param file 文件
* @return
*/
public static HttpPost getHttpPost(String url, JSONObject args, JSONObject params, File file) {
return getHttpPost(url + changeJsonToArguments(args), params, file);
}
/**
* 获取 httpPost 对象
* <p>方法重载,文字信息form表单提交,文件信息二进制流提交,具体参照文件上传的方法主食,post请求可以不需要参数,暂时不支持其他参数类型,如果是公参需要在url里面展示,需要传一个json对象,一般默认args为get公参,params为post请求参数</p>
*
* @param url 请求地址
* @param params 请求参数,其中二进制流必须是 file
* @param file 文件
* @return
*/
public static HttpPost getHttpPost(String url, JSONObject params, File file) {
HttpPost httpPost = getHttpPost(url);
setMultipartEntityEntity(httpPost, params, file);
return httpPost;
}
/**
* 设置二进制流实体,params 里面参数值为 file
*
* @param httpPost httpPsot 请求
* @para
没有合适的资源?快使用搜索试试~ 我知道了~
FunTester测试框架,接口功能、自动化、性能、元测试,mocoAPI、JsonPath、自定义工具类等。___下载.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共119个文件
java:76个
groovy:25个
markdown:8个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 34 浏览量
2023-04-18
00:13:12
上传
评论
收藏 200KB ZIP 举报
温馨提示
FunTester测试框架,接口功能、自动化、性能、元测试,mocoAPI、JsonPath、自定义工具类等。___下载.zip
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 119 条
- 1
- 2
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
快撑死的鱼
- 粉丝: 1w+
- 资源: 9152
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- Python和SQLite数据库实现一个简单的出入库系统.rar
- PySpark和Matplotlib绘制趋势图的简单示例.rar
- 实验5 用例图.docx
- 课程大作业基于python实现的单目双目视觉三维重建源码(95分以上).zip
- 使用matplotlib库绘制简单图表的例子.rar
- 九阴真经OL资源解包工具
- python-leetcode面试题解之第307题区域和检索.zip
- python-leetcode面试题解之第305题岛屿数量II.zip
- python-leetcode面试题解之第304题二维区域和检索.zip
- python-leetcode面试题解之第303题区域和检索.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)