要求在页面查询到5000条数据,为了方便插入,用shell脚本写curl命令调用本身写的代码接口;前端
脚本以下:java
#!/bin/bash a=0 while [ $a -le 10 ]; do # length of ts is 13 required,Through the following way like this ts=`date +%s%N` ts=${ts:0:13} json='{"name" : "'$1$a'", "age" : '$2', "ts" : '$ts'}' a=$((a+1)) curl -k -H 'Content-Type:application/json;charset=utf-8' http://192.168.2.5:8080 -X POST -d "'$json'" done
执行脚本python
sh batch_curl.sh gege 21
git
执行结果
github
该接口是用go语言提供的demo接口:以下:面试
copyrequestbody = true
package controller import ( "github.com/astaxie/beego" "fmt" ) type SayHelloController struct { beego.Controller } func (this *SayHelloController) SayHello(){ fmt.Println("RequestBody is ", string(this.Ctx.Input.RequestBody)) this.Ctx.Output.Header("Content-type", "application/json;charset=utf-8") this.Ctx.Output.SetStatus(200) this.Ctx.Output.Body(this.Ctx.Input.RequestBody) }
package router import ( "github.com/astaxie/beego" "sayHello/controller" ) var hello = controller.SayHelloController{} func init() { beego.Router("/", &hello, "POST:SayHello") }
package main import ( "github.com/astaxie/beego" _ "sayHello/router" "fmt" ) func main() { fmt.Println(beego.BConfig.CopyRequestBody) beego.Run() }
本公众号免费提供csdn下载服务,海量IT学习资源,若是你准备入IT坑,励志成为优秀的程序猿,那么这些资源很适合你,包括但不限于java、go、python、springcloud、elk、嵌入式 、大数据、面试资料、前端 等资源。同时咱们组建了一个技术交流群,里面有不少大佬,会不定时分享技术文章,若是你想来一块儿学习提升,能够公众号后台回复【2】,免费邀请加技术交流群互相学习提升,会不按期分享编程IT相关资源。spring
扫码关注,精彩内容第一时间推给你shell