没有合适的资源?快使用搜索试试~ 我知道了~
首页Python批量发送post请求的实现代码
资源详情
资源评论
资源推荐

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);
}
}



















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0