zoukankan      html  css  js  c++  java
  • 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
    

    批量curl脚本

    执行脚本

    sh batch_curl.sh gege 21

    执行结果
    10次curl执行结果

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

    • 目录结构:
      目录结构
    • 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()
    }
    



    本公众号免费提供csdn下载服务,海量IT学习资源,如果你准备入IT坑,励志成为优秀的程序猿,那么这些资源很适合你,包括但不限于java、go、python、springcloud、elk、嵌入式 、大数据、面试资料、前端 等资源。同时我们组建了一个技术交流群,里面有很多大佬,会不定时分享技术文章,如果你想来一起学习提高,可以公众号后台回复【2】,免费邀请加技术交流群互相学习提高,会不定期分享编程IT相关资源。


    扫码关注,精彩内容第一时间推给你

    image

  • 相关阅读:
    Windows 10 版本 1507 中的新 AppLocker 功能
    github 查询
    Facebook Paper使用的第三方库
    C#如何使用右下角托盘图标notifyIcon
    C#如何设置窗体不能修改大小
    C#如何让Listbox支持多选
    C#如何开发多语言支持的Winform程序
    C#如何发布项目 发布软件
    C#如何编辑tab选项卡
    C#如何把写好的类编译成dll文件
  • 原文地址:https://www.cnblogs.com/liabio/p/11707178.html
Copyright © 2011-2022 走看看