场景:
N多个参数,截取指定个数,拼接URL
java
public static void main(final String[] args) {
int count = 0;
//每页数量
final int pageSize = 5;
final List<Integer> memberNos = ListUtil.toList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
while (true) {
final int start = count * pageSize;
if (start >= memberNos.size()) {
break;
}
final int end = (count + 1) * pageSize > memberNos.size() ? memberNos.size() : (count + 1) * pageSize;
//拆LIST
final List<Integer> sonList = memberNos.subList(start, end);
//拼接url
final String url = "http://xxxxxx?" + sonList.stream().map(item -> item.toString()).collect(Collectors.joining(","));
//组装后的url
System.out.println(url);
count++;
}
}
linux shell脚本:
bash
#!/bin/bash
# 文件名
input file=$1
# 拼接的url前缀
url="http://xxxx'
# 读取一行
while IFS= read -r line
do
arr=($line)
memberList=s{arr[0]]
echo "para: $line" >> $input file.output
# post请求,参数名memberList
result=$(curl -d "[\"memberList ": [$memberlist]]" -H "Content-Type: application/json" -X POST "$url")
# 响应结果输出文件
echo "Result: $result" >> $input_file.output
echo "-----" >> $input_file.output
sleep 2
done < "$input_file"