qt 调用shell脚本_shell脚本批量调用接口

正文

要求在页面查询到5000条数据,为了方便插入,用shell脚本写curl命令调用自己写的代码接口;

脚本如下:

#!/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

9e99f1ceae9bdb406fd1aa2ddf38308c.png

执行脚本

sh batch_curl.sh  gege  21

执行结果

b568b4f6a1eb4ad27f11f64be84aaa3b.png

该接口是用go语言提供的demo接口:如下:

  • 目录结构:

44d8278859ddce516817ab27d738c240.png
  • app.conf
copyrequestbody = true
  • controller.go
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)
}
  • router.go
package router

import (
    "github.com/astaxie/beego"
    "sayHello/controller"
)

var hello = controller.SayHelloController{}

func init() {

    beego.Router("/", &hello, "POST:SayHello")
}
    • main.go
package main

import (
    "github.com/astaxie/beego"
    _ "sayHello/router"
    "fmt"
)

func main() {
    fmt.Println(beego.BConfig.CopyRequestBody)
    beego.Run()
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值