没有合适的资源?快使用搜索试试~ 我知道了~
首页Python批量发送post请求的实现代码
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/12869031/bg1.jpg)
Python批量发送批量发送post请求的实现代码请求的实现代码
昨天学了一天的Python(我的生产语言是java,也可以写一些shell脚本,算有一点点基础),今天有一个应用
场景,就正好练手了
昨天学了一天的Python(我的生产语言是java,也可以写一些shell脚本,算有一点点基础),今天有一个应用场景,就正好练
手了。
这个功能之前再java里写过,比较粗糙,原来是在我本机跑的,今天老大要求要随时保持请求,就用Python改写了下,省的又
把一个有跟多杂项的jar包传到服务器,省空间又不乱,而且好读。
先附上java代码:
package xxxxxx.base;
import java.util.Random;
import org.apache.commons.lang3.StringUtils;
import haojianxiang.util.HttpRequest;
public class CreateFeedbackData {
public static void main(String[] args) {
while (true) {
try {
Random r = new Random();
int sleep = r.nextInt(1200000) + 600000;
Thread.sleep(sleep);
post();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void post(){
String url = "http://111.111.111.111:8080/xxxx/post";
int[] types = {1, 2, 3, 4};
int index = (int) (Math.random() * types.length);
int type = types[index];
// String[] contents = {"-中文测试-,","-English Test-,","~!@#$%^&*()_;:'-\"<>?/|\-,"," "};
String[] contents = {"-中文测试-,","-English Test-,","~!@#$%,"," "};
StringBuffer content = new StringBuffer();
content.append("haojianxiang test:");
for (int i = 0; i < 10; i++) {
int idx = (int) (Math.random() * contents.length);
content.append(contents[idx]);
}
String[] imgs = {"/Upload/appUpload/58c7b315cb39f.jpg",
"/Upload/appUploa/58cb467a69873.jpg",
"/Upload/appUpload/58afff0e99432.png",
"/Upload/appUpload/58b545539eb80.jpg",
"/Upload/appUpload/58b55d7c9e281.JPG",
};
StringBuffer img = new StringBuffer();
for (int i = 0; i < (int) (Math.random() * 4); i++) {
int lucky = (int) (Math.random() * 2);
if (lucky == 1) {
int idx = (int) (Math.random() * imgs.length);
img.append(imgs[idx]);
img.append(",");
}
}
String imgStr = "";
if (StringUtils.isNotBlank(img)) {
imgStr = img.substring(0, img.length()-1);
}
String param = "{\"req\":{\"userId\":xxxxxx}," +
"\"data\":{"\"fbType\":" + type + ",\"fbContent\":\""+content.toString()+
"\",\"fbPic\":\""+imgStr+"\"}}";
String rst = HttpRequest.sendPost(url, param);
System.out.println("TIME--"+ System.currentTimeMillis() + " result:" + rst);
}
}
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/default.jpg!1)
weixin_38526208
- 粉丝: 3
- 资源: 940
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
会员权益专享
最新资源
- 基于单片机的瓦斯监控系统硬件设计.doc
- 基于单片机的流量检测系统的设计_机电一体化毕业设计.doc
- 基于单片机的继电器设计.doc
- 基于单片机的湿度计设计.doc
- 基于单片机的流量控制系统设计.doc
- 基于单片机的火灾自动报警系统毕业设计.docx
- 基于单片机的铁路道口报警系统设计毕业设计.doc
- 基于单片机的铁路道口报警研究与设计.doc
- 基于单片机的流水灯设计.doc
- 基于单片机的时钟系统设计.doc
- 基于单片机的录音器的设计.doc
- 基于单片机的万能铣床设计设计.doc
- 基于单片机的简易安防声光报警器设计.doc
- 基于单片机的脉搏测量器设计.doc
- 基于单片机的家用防盗报警系统设计.doc
- 基于单片机的简易电子钟设计.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)